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起效,不知道这是为什么

相关推荐
被遗忘在角落的死小孩1 小时前
抗量子 Winternitz One Time Signature(OTS) 算法学习
学习·算法·哈希算法
浅念-1 小时前
C++ :类和对象(4)
c语言·开发语言·c++·经验分享·笔记·学习·算法
xixixi777771 小时前
零样本学习 (Zero-Shot Learning, ZSL)补充
人工智能·学习·安全·ai·零样本·模型训练·训练
特立独行的猫a2 小时前
Kuikly多端框架(KMP)实战:KMP中的 Ktor 网络库的多端适配指南
android·网络·harmonyos·ktor·compose·kmp·kuikly
AI视觉网奇2 小时前
ue 推送直播流 推流 linux 实战
笔记·学习·ue5
Mr YiRan2 小时前
C++语言学习之面向对象
java·c++·学习
kkkkkkkkk_12012 小时前
【强化学习】09周博磊强化学习纲要学习笔记——第五课上
笔记·深度学习·学习·强化学习
玩c#的小杜同学2 小时前
工业级稳定性:如何利用生产者-消费者模型(BlockingCollection)解决串口/网口高频丢包问题?
笔记·学习·性能优化·c#·软件工程
一品威客网3 小时前
教育 APP 升级!跨端开发支持“多设备学习,无缝衔接”
学习
瑶光守护者3 小时前
【学习笔记】3GPP NR-NTN 移动性IRAT分析
笔记·学习·卫星通信·nr-ntn