一。主题的创建
/res/values/stytles.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<resources> <!-- 自定义的主题 --> <style name="text_content_style"> <!-- name=控件的属性 --> <item name="android:layout_width">wrap_content</item> <item name="android:layout_height">wrap_content</item> <item name="android:textColor">#0000ff</item> <item name="android:textSize">20sp</item> </style> <!-- 样式和主题的区别,作用范围不同,样式都是作用在一个小控件, 主题作用一个activity,或者整个应用程序 样式都在布局文件里面配置,主题都在 /res/values/stytles.xml 清单文件配置 --> <style name="red_bg_theme"> <item name="android:background">#33ff0000</item> </style> </resources> |
二。控件主题(样式)更改
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<LinearLayout> <TextView style="@style/text_content_style" android:text="使用自定义主题" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="#fff000" android:background="#aaa999" android:onClick="click4" android:text="使用自身样式" /> </LinearLayout> |
三。界面和应用的主题
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<manifest> <application <!-- theme定义在application节点,对整个应用的全部界面起作用 --> android:theme="@style/red_bg_theme" android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity <!-- theme定义在activity节点,仅对此界面起作用 --> android:theme="@style/red_bg_theme" android:name="com.itheima.styletheme.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> |
声明
本文由崔维友 威格灵 cuiweiyou vigiles cuiweiyou 原创,转载请注明出处:http://www.gaohaiyan.com/405.html
承接App定制、企业web站点、办公系统软件 设计开发,外包项目,毕设