★13.Style&Theme

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"/>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容