Android修改系统默认的颜色

Android修改系统默认的颜色

1.默认颜色的参考

感谢博主文章:https://www.cnblogs.com/steffen/p/9261977.html

1.安卓的界面主题颜色分布

2.常见的颜色:

  1. colorPrimary:应用的主要色调,ActionBar 默认使用该颜色,Toolbar 导航栏的底色;
  2. colorPrimaryDark:应用的主要暗色调,statusBarColor默认使用该颜色;
  3. statusBarColor:状态栏颜色,默认使用colorPrimaryDark;
  4. windowBackground:窗口背景颜色;
  5. navigationBarColor:底部栏颜色;
  6. colorForeground:应用的前景色,ListView 的分割线,switch 滑动区默认使用该颜色;
  7. colorBackground:应用的背景色,popMenu 的背景默认使用该颜色;
  8. colorAccent:CheckBox,RadioButton,SwitchCompat 等一般控件的选中效果默认采用该颜色;
  9. colorControlNormal:CheckBox,RadioButton,SwitchCompat 等默认状态的颜色;
  10. colorControlHighlight:控件按压时的色调;
  11. colorControlActivated:控件选中时的颜色,默认使用 colorAccent;
  12. colorButtonNormal:默认按钮的背景颜色;
  13. editTextColor:默认EditView输入框字体的颜色;
  14. textColor:Button,TextView 的文字颜色;
  15. textColorPrimaryDisableOnly: RadioButton、Checkbox 等控件的文字;
  16. textColorPrimary:应用的主要文字颜色,ActionBar 的标题文字默认使用该颜色;
  17. colorSwitchThumbNormal: switch thumbs 默认状态的颜色 (switch off)。

2.修改系统默认的颜色

1.修改系统默认颜色的步骤

第一步:创建一个activity

第二步:找到res-values-themes下的themes.xml文件

themes.xml文件默认的代码如下:

<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    <style name="Theme.MyApplication3" parent="Theme.MaterialComponents.DayNight.DarkActionBar.Bridge">
        <!-- Primary brand color. -->
        <item name="colorPrimary">@color/purple_500</item>
        <item name="colorPrimaryVariant">@color/purple_700</item>
        <item name="colorOnPrimary">@color/white</item>
        <!-- Secondary brand color. -->
        <item name="colorSecondary">@color/teal_200</item>
        <item name="colorSecondaryVariant">@color/teal_700</item>
        <item name="colorOnSecondary">@color/black</item>
        <!-- Status bar color. -->
        <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
        <!-- Customize your theme here. -->
    </style>
</resources>

第三步:编写布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".andorid_Theme">
<!--修改系统默认的颜色-->
<CheckBox
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="你好"
    />
    <RadioGroup
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        >
        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="男"
            />
        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="女"
            />
    </RadioGroup>
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="text"
        />
</LinearLayout>

第四步:修改后的颜色

<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    <style name="Theme.MyApplication3" parent="Theme.MaterialComponents.DayNight.DarkActionBar.Bridge">
        <!-- Primary brand color. -->
        <!--       最顶部颜色 -->
        <item name="colorPrimaryDark">@color/purple_700</item>
<!--        顶部的颜色-->
        <item name="colorPrimary">@color/purple_500</item>
<!--    顶部文字的颜色-->
        <item name="android:textColorPrimary">@color/teal_700</item>
<!--        <item name="colorOnPrimary">@color/white</item>-->
        <!-- Secondary brand color. -->
        <item name="colorSecondary">@color/teal_200</item>
        <item name="colorSecondaryVariant">@color/teal_700</item>
<!--        底部导航栏的颜色-->
        <item name="colorOnSecondary">@color/black</item>
        <!-- Status bar color. -->
        <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
        <!-- Customize your theme here. -->
<!--        底部导航栏的颜色-->
        <item name="colorAccent">@color/black</item>
        <item name="android:navigationBarColor">@color/black</item>
<!--        窗口背景颜色-->
        <item name="android:windowBackground">@color/teal_200</item>
    </style>
</resources>

第五步:效果图

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不懂代码的孩子

谢谢大佬

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值