Android主题(theme)与样式(style)
4827 点击·0 回帖
![]() | ![]() | |
![]() | 主题和样式有什么不同? 主题:Theme是针对窗体级别的,改变窗体样式。在application和activity标签下使用。 样式:Style是针对窗体元素级别的,改变指定控件或者Layout的样式。在具体控件下使用。 主题和样式可以用Android系统自带的 也可以自定义。下面讲讲怎么自定义主题和样式。 具体步骤: 在res/values目录下新建一个名叫style.xml的文件 对于每一个主题和样式,给<style>元素增加一个全局唯一的名字,和一个可选的父类属性 在<style>元素内部,申明一个或者多个<item>,每一个<item>定义了一个名字属性,并且在元素内部定义了这个风格的值 然后可以在其他XML资源,manifest或应用程序代码中引用这些自定义资源 样式例子: [html] <style name="textview_style01"> <item name="android:layout_width">fill_parent</item> <item name="android:layout_height">fill_parent</item> <item name="android:gravity">center</item> <item name="”android:textSize”">14sp</item> <item name="”android:textColor”">#FF7F7C</item> </style> <style name="textview_style02" parent="@style/textview_style01"> <item name="”android:textSize”">28sp</item> </style> <style name="textview_style01"> <item name="android:layout_width">fill_parent</item> <item name="android:layout_height">fill_parent</item> <item name="android:gravity">center</item> <item name="”android:textSize”">14sp</item> <item name="”android:textColor”">#FF7F7C</item> </style> <style name="textview_style02" parent="@style/textview_style01"> <item name="”android:textSize”">28sp</item> </style>[html] view plaincopyprint?<TextView style="@style/textview_style01"></TextView> <TextView style="@style/textview_style01"></TextView> 主题例子 [html] <style name="my_theme" parent="android:Theme.Black"> <item name="”android:windowNoTitle”">true</item> <item name="”android:textSize”">14sp</item> <item name="”android:textColor”">#FFFF0000</item> </style> <style name="my_theme" parent="android:Theme.Black"> <item name="”android:windowNoTitle”">true</item> <item name="”android:textSize”">14sp</item> <item name="”android:textColor”">#FFFF0000</item> </style>[html] view plaincopyprint?<application android:theme="@style/my_theme"> <activity android:theme="@style/my_theme"> www.atcpu.com <application android:theme="@style/my_theme"> <activity android:theme="@style/my_theme"> | |
![]() | ![]() |