android给控件着色,Android 5.0以上系统常用控件着色指南

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

@color/colorPrimary

@color/colorPrimaryDark

@color/colorAccent

colorPrimary,colorPrimaryDark,colorAccent大家应该都已经非常熟悉了,分别控制如下界面中的颜色

20170420201313_108.jpg

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

colorControlHighlight

colorControlHighlight用于控制 所有可点击的View 的涟漪效果颜色,以button举例来说

普通状态下的button

20170420201313_915.gif

现在我们在AppTheme中添加下面这条属性

@color/colorAccent

20170420201313_550.gif

colorButtonNormal

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

设置colorButtonNormal后button的normal状态如下

20170420201313_950.gif

android:navigationBarColor

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

20170420201313_915.png

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

EditText

unfocused —— colorControlNormal

focus —— colorAccent

cursor —— colorAccent

text color —— android:textColorPrimary

RadioButton

unselected —— colorControlNormal

selected —— colorAccent

CheckBox

box unchecked —— colorControlNormal

box checked —— colorAccent

Toolbar

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

ActionBar

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

Spinner

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"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值