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

相关推荐
咸甜适中10 分钟前
rust语言 (1.88) 学习笔记:客户端和服务器端同在一个项目中
笔记·学习·rust
灿烂阳光g15 分钟前
domain_auto_trans,source_domain,untrusted_app
android·linux
Magnetic_h1 小时前
【iOS】设计模式复习
笔记·学习·ios·设计模式·objective-c·cocoa
研梦非凡2 小时前
ICCV 2025|从粗到细:用于高效3D高斯溅射的可学习离散小波变换
人工智能·深度学习·学习·3d
低调小一2 小时前
Android传统开发 vs Android Compose vs HarmonyOS ArkUI 对照表
android·华为·harmonyos
雨白2 小时前
Java 多线程指南:从基础用法到线程安全
android·java
Hungry_Shark2 小时前
IDEA版本控制管理之使用Gitee
java·gitee·intellij-idea
limengshi1383923 小时前
机器学习面试:请介绍几种常用的学习率衰减方式
人工智能·学习·机器学习
知识分享小能手3 小时前
React学习教程,从入门到精通,React 组件核心语法知识点详解(类组件体系)(19)
前端·javascript·vue.js·学习·react.js·react·anti-design-vue
00后程序员张3 小时前
详细解析苹果iOS应用上架到App Store的完整步骤与指南
android·ios·小程序·https·uni-app·iphone·webview