style 和theme

1,style 和 theme 的区别:

When you apply a style to a single View in the layout, the properties defined by the style are applied only to that View. If a style is applied to a ViewGroup, the child View elements will not inherit the style properties—only the element to which you directly apply the style will apply its properties. However, you can apply a style so that it applies to all View elements—by applying the style as a theme.html

To apply a style definition as a theme, you must apply the style to an Activity or application in the Android manifest. When you do so, every View within the Activity or application will apply each property that it supports. For example, if you apply the CodeFont style from the previous examples to an Activity, then all View elements that support the text style properties will apply them. Any View that does not support the properties will ignore them. If a View supports only some of the properties, then it will apply only those properties.android

2,引用样式属性app

Referencing style attributeside

(@ 与 ? 的区别)工具

您能够经过样式属性资源在当前应用的风格主题中引用某个属性的值。 经过引用样式属性,您能够不采用为 UI 元素提供硬编码值这种方式,而是经过为 UI 元素设置样式,使其匹配当前风格主题提供的标准变型来定制这些元素的外观。引用样式属性的实质做用是,“在当前风格主题中使用此属性定义的样式”。ui

要引用样式属性,名称语法几乎与普通资源格式彻底相同,只不过将 at 符号 (@) 改成问号 (?),资源类型部分为可选项。 例如:编码

?[<package_name>:][<resource_type>/]<resource_name>

例如,您能够经过如下代码引用一个属性,将文本颜色设置为与系统风格主题的“主要”文本颜色匹配:spa

<EditText id="text"
   
android:layout_width="fill_parent"
   
android:layout_height="wrap_content"
   
android:textColor="?android:textColorSecondary"
   
android:text="@string/hello_world" />

在以上代码中,android:textColor 属性表示当前风格主题中某个样式属性的名称。Android 如今会使用应用于 android:textColorSecondary 样式属性的值做为 android:textColor 在这个小工具中的值。因为系统资源工具知道此环境中确定存在某个属性资源,所以您无需显式声明类型(类型应为 ?android:attr/textColorSecondary)— 您能够将 attr 类型排除在外。code

相关文章
相关标签/搜索