Android 样式与主题背景学习

设置主题

主题在Androidmanifest.xml中设置

html 复制代码
    <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颜色都会改变

html 复制代码
<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的风格,于是添加如下代码

html 复制代码
<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起效,不知道这是为什么

相关推荐
sunshine22 girl6 小时前
Java学习六 Java常见API-2--String-3-字符串的截取替换和其他方法
java·开发语言·学习
sunshine22 girl6 小时前
Java学习六 Java常见API-1-Radom随机数
java·开发语言·学习
Answer1st7 小时前
【嵌入式学习】嵌入式原理知识-DMA(九)
学习
传奇开心果编程7 小时前
【ArkUI进阶练中学】第11课:安全与合规进阶
学习·ui·华为·harmonyos
Mr_Macallon9 小时前
C++回顾(基础)(01)
c语言·开发语言·c++·学习
五彩小白10 小时前
自回归和上下文
android
sunoo-22910 小时前
【ARM嵌入式学习笔记第十天】i.MX6ULL eLCDIF控制器驱动RGB LCD全解析(硬件原理+寄存器配置+裸机代码)
arm开发·笔记·学习
kaiyou202611 小时前
用户研究岗秋招,统计分析能力怎么学习和证明?
数据库·python·学习
知识分享小能手11 小时前
C++ 学习教程,从入门到精通,string类和标准模板库 — 完整知识点详解(16)
开发语言·c++·学习
事圆则缓12 小时前
Android 多渠道打包实战:Product Flavors、签名、AAB 与发包校验
android