Android 样式与主题背景学习

设置主题

主题在Androidmanifest.xml中设置

    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.SIM" <!--this-->
        tools:targetApi="29">
        <activity
            android:name=".NotificationActivity"
            android:exported="false" />
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

样式和主题在 res/values/ 中的样式说明文件(themes.xml)声明。

以下是我的应用的主题声明,colorPrimary属性能改变主题颜色,修改后状态栏以及Button颜色都会改变

<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    <style name="Base.Theme.SIM" parent="Theme.Material3.DayNight.NoActionBar">
        <!-- Customize your light theme here. -->
         <item name="colorPrimary">#468347</item>
    </style>

    <style name="Theme.SIM" parent="Base.Theme.SIM" />
</resources>

在声明了主题之后我想试试统一Button的风格,于是添加如下代码

<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    <style name="Base.Theme.SIM" parent="Theme.Material3.DayNight.NoActionBar">
        <!-- Customize your light theme here. -->
         <item name="colorPrimary">#468347</item>
        <item name="buttonStyle">@style/Button</item>
    </style>

    <style name="Theme.SIM" parent="Base.Theme.SIM" />
    <style name="Button" parent="@style/Widget.AppCompat.Button">
        <item name="android:textColor">#784897</item>
        <item name="minWidth">100dp</item>
        <item name="backgroundColor">#898089</item>
    </style>
</resources>

但<item name="buttonStyle">@style/Button</item>这种用法并没有对button起效,不知道这是为什么

相关推荐

  1. Android 样式主题背景学习

    2023-12-10 13:38:02       37 阅读
  2. Android设置夜间模式的主题样式

    2023-12-10 13:38:02       34 阅读
  3. 一次讲透 CSS 背景样式

    2023-12-10 13:38:02       9 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-10 13:38:02       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-10 13:38:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-10 13:38:02       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-10 13:38:02       20 阅读

热门阅读

  1. 华为机试真题 C++ 实现【字符串重新排列】

    2023-12-10 13:38:02       38 阅读
  2. react

    react

    2023-12-10 13:38:02      37 阅读
  3. 软考 系统架构设计师系列知识点之大数据(3)

    2023-12-10 13:38:02       42 阅读
  4. C++知识 抽象基类

    2023-12-10 13:38:02       41 阅读
  5. CSS中的水平垂直居中元素的多种方式

    2023-12-10 13:38:02       46 阅读
  6. 高防IP防御效果怎么样,和VPN有区别吗

    2023-12-10 13:38:02       35 阅读
  7. Metasploit在蓝队防御中的应用

    2023-12-10 13:38:02       25 阅读
  8. Tmux中使用Docker报错 - 解决方案

    2023-12-10 13:38:02       40 阅读
  9. ubuntu串口永久权限

    2023-12-10 13:38:02       36 阅读
  10. Http常见的状态码

    2023-12-10 13:38:02       29 阅读
  11. 函数的参数

    2023-12-10 13:38:02       34 阅读