本帖最後由 tonyh 於 2018-7-21 17:40 編輯
style 的配置是針對元件,若要統一配置整頁(activity)或整個app的風格,則需要使用theme(主題)來控制。試著練習以「Theme Editor」調配出兩個不同風格的介面。
AndroidManifest.xml- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.example.student.myapplication" >
- <application
- android:allowBackup="true"
- android:icon="@mipmap/ic_launcher"
- android:label="@string/app_name"
- android:supportsRtl="true"
- android:theme="@style/MyTheme02" >
- <activity android:name=".MainActivity" >
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
- </manifest>
複製代碼 values/styles.xml- <resources>
- <!-- Base application theme. -->
- <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
- <!-- Customize your theme here. -->
- <item name="colorPrimary">@color/colorPrimary</item>
- <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
- <item name="colorAccent">@color/colorAccent</item>
- </style>
- <style name="MyTheme01" parent="@android:style/Theme.Holo">
- <!-- Customize your theme here. -->
- </style>
- <style name="MyTheme02" parent="@android:style/Theme.Material.Light">
- <!-- Customize your theme here. -->
- <item name="android:colorForeground">@color/foreground_material_light</item>
- <item name="android:textColorPrimary">@color/primary_text_material_light</item>
- <item name="android:colorPrimaryDark">@color/primary_dark_material_light</item>
- <item name="android:colorPrimary">@color/primary_material_light</item>
- <item name="android:colorAccent">@color/accent_material_light</item>
- </style>
- <style name="Style01">
- <item name="android:background">#e20000</item>
- <item name="android:textColor">#fff0f0</item>
- <item name="android:textSize">30sp</item>
- <item name="android:gravity">center</item>
- </style>
- <style name="Style02" parent="Style01">
- <item name="android:background">#006de2</item>
- <item name="android:textColor">#f0f6ff</item>
- <item name="android:layout_marginTop">10dp</item>
- </style>
- </resources>
複製代碼 |