Theme
自定義主題
在 res/values/styles.xml 文件中:
<style name="AppTheme" parent="Theme.AppCompat">
<item name="colorPrimary">@color/red</item>
</style>
應(yīng)用主題
在 AndroidManifest.xml 文件中:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
</application>
AppCompat庫(kù)自帶三大主題
- 深色主題:
Theme.AppCompat
- 淺色主題:
Theme.AppCompat.Light
- 帶深色工具欄的淺色主題:
Theme.AppCompat.Light.DarkActionBar
Style
在 res/values/styles.xml 文件中:
添加樣式
<style name="BeatBoxButton">
<item name="android:background">@color/dark_blue</item>
</style>
繼承樣式
方式一
<style name="StrongBeatBoxButton" parent="@style/BeatBoxButton">
<item name="android:textStyle">bold</item>
</style>
方式二
<style name="BeatBoxButton.Strong">
<item name="android:textStyle">bold</item>
</style>
注意事項(xiàng)
- 跨庫(kù)繼承只能使用 方式一 。
使用樣式
<Button xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
style="@style/BeatBoxButton"
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="120dp"
tools:text="Sound name"/>