Android修改系统默认的颜色
1.默认颜色的参考
感谢博主文章:https://www.cnblogs.com/steffen/p/9261977.html
1.安卓的界面主题颜色分布
2.常见的颜色:
- colorPrimary:应用的主要色调,ActionBar 默认使用该颜色,Toolbar 导航栏的底色;
- colorPrimaryDark:应用的主要暗色调,statusBarColor默认使用该颜色;
- statusBarColor:状态栏颜色,默认使用colorPrimaryDark;
- windowBackground:窗口背景颜色;
- navigationBarColor:底部栏颜色;
- colorForeground:应用的前景色,ListView 的分割线,switch 滑动区默认使用该颜色;
- colorBackground:应用的背景色,popMenu 的背景默认使用该颜色;
- colorAccent:CheckBox,RadioButton,SwitchCompat 等一般控件的选中效果默认采用该颜色;
- colorControlNormal:CheckBox,RadioButton,SwitchCompat 等默认状态的颜色;
- colorControlHighlight:控件按压时的色调;
- colorControlActivated:控件选中时的颜色,默认使用 colorAccent;
- colorButtonNormal:默认按钮的背景颜色;
- editTextColor:默认EditView输入框字体的颜色;
- textColor:Button,TextView 的文字颜色;
- textColorPrimaryDisableOnly: RadioButton、Checkbox 等控件的文字;
- textColorPrimary:应用的主要文字颜色,ActionBar 的标题文字默认使用该颜色;
- 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>
第五步:效果图