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

相关推荐
青山是哪个青山8 小时前
LangChain 学习笔记(四):Message 与提示词模板
笔记·学习·langchain
hsjiasb9 小时前
FreeRTOS学习(二十六)——动态内存管理heap_1到heap_5
stm32·单片机·学习·学习笔记·freertos
崇子嵘9 小时前
基于zynqMP15eg的linux驱动学习
学习
知识分享小能手11 小时前
线性代数学习教程,从入门到精通,向量组的线性相关性 — 完整知识点梳理(7)
学习·线性代数·机器学习
Shell运维手记11 小时前
Linux 常用基础命令学习笔记
linux·运维·笔记·学习·算法·github
动词ing12 小时前
【学习笔记】C语言(数组指针与指针数组+字符数组+函数+参数传递+字符串作为形参+递归函数+指针函数+回调函数+结构体嵌套+内存动态分配函数)
c语言·笔记·学习
小O的算法实验室14 小时前
IEEE TII,学习为多目标深度学习生成偏好
人工智能·深度学习·学习
wxson728214 小时前
【Android视频监控系统技术总结】
android·音视频
吃好睡好便好15 小时前
说说高温对情绪的影响
学习·生活·情绪·高温