Android 5.0以上系统经常使用控件着色指南

当咱们新建一个Android工程时,Android studio会默认的给咱们生成一个AppTheme,内容以下javascript

<resources>

    <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style> </resources>复制代码

colorPrimary,colorPrimaryDark,colorAccent你们应该都已经很是熟悉了,分别控制以下界面中的颜色java

下面咱们要说的是其余一些和颜色相关的属性,这些属性可能你平时并不经常使用,但合理运用它们不只能够使你的界面更加绚丽并且能够达到事半功倍的效果。(再次声明如下属性适用于5.0及其以上系统)android

colorControlHighlight
colorControlHighlight用于控制全部可点击的View的涟漪效果颜色,以button举例来讲
普通状态下的button
app


如今咱们在AppTheme中添加下面这条属性

<item name="colorControlHighlight">@color/colorAccent</item>复制代码


colorButtonNormal
用于控制 normal状态下button的颜色(注意和button的background属性的区别,设置colorButtonNormal后button依旧会具备涟漪效果,而设置background就没有涟漪效果了)
设置colorButtonNormal后button的normal状态以下

android:navigationBarColor
控制底部导航栏的背景色(注意前边必须有android:),例如:

下面说一下经常使用控件的颜色属性

EditText布局

  • unfocused —— colorControlNormal
  • focus —— colorAccent
  • cursor —— colorAccent
  • text color —— android:textColorPrimary

RadioButtonspa

  • unselected —— colorControlNormal
  • selected —— colorAccent

CheckBox3d

  • box unchecked —— colorControlNormal
  • box checked —— colorAccent

Toolbar code

  • background —— 布局文件中设置android:background="?attr/colorPrimary
  • overflow icon —— android:textColorPrimary
  • navigation icon —— android:textColorPrimary
  • action icons —— android:textColorPrimary
  • overflow menu background —— android:colorBackground
  • overflow text color —— android:textColorPrimary

ActionBarregexp

  • background —— colorPrimary
  • title color —— android:textColorPrimary
  • overflow icon —— android:textColorPrimary
  • up button —— android:textColorPrimary
  • action icons —— android:textColorPrimary
  • overflow menu background —— android:colorBackground
  • overflow text color —— android:textColorPrimary

Spinnerorm

  • indicator (not pressed) —— colorControlNormal
  • indicator (pressed) —— colorAccent
  • selected entry text color —— "android:textColorPrimary

SwitchCompat

  • thumb switch off —— colorSwitchThumbNormal
  • thumb switch on —— colorAccent
  • track overlay —— colorAccent"
相关文章
相关标签/搜索