样式
1、视图
1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:orientation="vertical" 6 tools:context=".MainActivity" > 7 8 <TextView 9 style="@style/text_content_style_night" 10 android:text="我是一个文本" /> 11 12 </LinearLayout>
2、样式文件在styles.xml文件中
1 <resources> 2 3 <!-- 4 Base application theme, dependent on API level. This theme is replaced 5 by AppBaseTheme from res/values-vXX/styles.xml on newer devices. 6 --> 7 <style name="AppBaseTheme" parent="android:Theme.Light"> 8 <!-- 9 Theme customizations available in newer API levels can go in 10 res/values-vXX/styles.xml, while customizations related to 11 backward-compatibility can go here. 12 --> 13 </style> 14 15 <!-- Application theme. --> 16 <style name="AppTheme" parent="AppBaseTheme"> 17 <!-- All customizations that are NOT specific to a particular API-level can go here. --> 18 </style> 19 20 <style name="text_content_style_day"> 21 <item name="android:textSize">20sp</item> 22 <item name="android:textColor">#ff0000</item> 23 <item name="android:layout_width">wrap_content</item> 24 <item name="android:layout_height">wrap_content</item> 25 </style> 26 27 <style name="text_content_style_night"> 28 <item name="android:background">#000000</item> 29 <item name="android:textSize">20sp</item> 30 <item name="android:textColor">#ff0000</item> 31 <item name="android:layout_width">wrap_content</item> 32 <item name="android:layout_height">wrap_content</item> 33 </style> 34 35 <style name="text_content_style_dark" parent="@style/text_content_style_night"> 36 <item name="android:background">#0000ff</item> 37 </style> 38 39 </resources>
注意:最后一个样式是说明它们之间的继承关系的

浙公网安备 33010602011771号