當(dāng)我們新建一個(gè)Android工程時(shí)贰盗,Android studio會(huì)默認(rèn)的給我們生成一個(gè)AppTheme,內(nèi)容如下
<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大家應(yīng)該都已經(jīng)非常熟悉了,分別控制如下界面中的顏色
下面我們要說(shuō)的是其他一些和顏色相關(guān)的屬性并级,這些屬性可能你平時(shí)并不常用拂檩,但合理運(yùn)用它們不僅可以使你的界面更加絢麗而且可以達(dá)到事半功倍的效果。(再次聲明以下屬性適用于5.0及其以上系統(tǒng))
colorControlHighlight
colorControlHighlight用于控制所有可點(diǎn)擊的View的漣漪效果顏色嘲碧,以button舉例來(lái)說(shuō)
普通狀態(tài)下的button
現(xiàn)在我們?cè)贏ppTheme中添加下面這條屬性
<item name="colorControlHighlight">@color/colorAccent</item>
colorButtonNormal
用于控制normal狀態(tài)下button的顏色(注意和button的background屬性的區(qū)別稻励,設(shè)置colorButtonNormal后button依舊會(huì)具有漣漪效果,而設(shè)置background就沒(méi)有漣漪效果了)
設(shè)置colorButtonNormal后button的normal狀態(tài)如下
android:navigationBarColor
控制底部導(dǎo)航欄的背景色(注意前邊必須有android:)愈涩,例如:
下面說(shuō)一下常用控件的顏色屬性
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 —— 布局文件中設(shè)置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"