標籤:
簡單練習自訂樣式和主題,樣式是加在View上,主題是加在Application或者Activity上
styles.xml
<?xml version="1.0" encoding="utf-8"?><resources xmlns:android="http://schemas.android.com/apk/res/android"> <!-- 自訂樣式 --> <style name="MyFont"> <item name="android:textColor">#ff0000</item> <item name="android:textSize">40sp</item> </style> <style name="MyFontSon" parent="@style/MyFont"> <item name="android:textSize">30sp</item> </style> <!-- 自訂佈景主題 --> <style name="MyTheme"> <item name=‘android:windowNoTitle‘>true</item> <item name="android:background">#ffffff</item> </style></resources>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView style="@style/MyFont" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="樣式和主題" /> <TextView style="@style/MyFontSon" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="樣式和主題" /></LinearLayout>
Manifest.xml
<application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="ss" android:theme="@style/MyTheme" >
[android] 安卓自訂樣式和主題