★13.Style&Theme

Theme

自定义主题

res/values/styles.xml 文件中:

<style name="AppTheme" parent="Theme.AppCompat">
    <item name="colorPrimary">@color/red</item>
</style>

应用主题

AndroidManifest.xml 文件中:

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
</application>

AppCompat库自带三大主题

  • 深色主题: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>

注意事项

  • 跨库继承只能使用 方式一

使用样式

<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"/>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容