當我們新建一個Android工程時,Android studio會默認的給我們生成一個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)非常熟悉了,分別控制如下界面中的顏色

下面我們要說的是其他一些和顏色相關(guān)的屬性,這些屬性可能你平時并不常用,但合理運用它們不僅可以使你的界面更加絢麗而且可以達到事半功倍的效果。(再次聲明以下屬性適用于5.0及其以上系統(tǒng))
colorControlHighlight
colorControlHighlight用于控制所有可點擊的View的漣漪效果顏色,以button舉例來說
普通狀態(tài)下的button

現(xiàn)在我們在AppTheme中添加下面這條屬性
<item name="colorControlHighlight">@color/colorAccent</item>

colorButtonNormal
用于控制normal狀態(tài)下button的顏色(注意和button的background屬性的區(qū)別,設(shè)置colorButtonNormal后button依舊會具有漣漪效果,而設(shè)置background就沒有漣漪效果了)
設(shè)置colorButtonNormal后button的normal狀態(tài)如下

android:navigationBarColor
控制底部導(dǎo)航欄的背景色(注意前邊必須有android:),例如:
下面說一下常用控件的顏色屬性
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"