修改styles.xml
相關屬性說明
1.colorPrimary: Toolbar導航欄的底色。
2.colorPrimaryDark:狀態欄的底色,注意這里只支持Android5.0以上的手機。
3.textColorPrimary:整個當前Activity的字體的默認顏色。
4.android:windowBackground:當前Activity的窗體顏色。
5.colorAccent:CheckBox,RadioButton,SwitchCompat等控件的點擊選中顏色
6.colorControlNormal:CheckBox,RadioButton,SwitchCompat等默認狀態的顏色。
7.colorButtonNormal:默認狀態下Button按鈕的顏色。
8.editTextColor:默認EditView輸入框字體的顏色。
一、Flat Button
一個在按下的時候會展現墨水散開的效果但沒有凸起效果由墨水形成的按鈕。
在layout.xml內的任意位置聲明你的 Button並設置 Borderless樣式.
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
style="@style/Widget.AppCompat.Button.Borderless"/>
如何設置樣式?
在你的 styles.xml內定義自定義樣式。
通過 android:theme屬性應用這個樣式到你的 Button。
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:theme="@style/MyButton"
style="@style/Widget.AppCompat.Button.Borderless"/>
二、Raised Button
一個典型的矩形 material 按鈕在手指抬起和按下的時候會展現墨水在紙上散開的效果。
在layout.xml內的任意位置聲明你的 Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"/>
如何設置樣式?
在你的styles.xml內定義自定義樣式。
通過 android:theme屬性應用這個樣式到你的 Button。
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:theme="@style/MyButton"/>
兼容性問題
I. 切換 Button
按下狀態的顏色你可以使用主題的 colorControlHighlight
屬性,雖然它僅僅影響 Lollipop 版本的系統。
II. Android elevation
只在 Lollipop 設備上有效,因此你在 Lollipop 之前的設備上將看不到 Button
周圍的陰影。
三、Radio Button
在layout.xml文件內任意位置聲明你的RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Radio Button"/>
如何設置樣式?
在 styles.xml文件內聲明你的自定義樣式.
通過 android:theme屬性將這個樣式應用到你的 RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Radio Button"
android:theme="@style/MyRadioButton"/>
四、Switch
On/off Switches 切換可以設置單選狀態。開關控制的選項,以及它所處的狀態,應該通過與它對應一致的內部標簽明確地展示出來,以達到與 radio button(單選按鈕)相同的視覺效果。
on/off 滑動開關用文字標示 “on” 和 “off” 的做法已被棄用。請用文首所示圖例來代替。
在任意的layout.xml文件內聲明你的SwitchCompat 。
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true" />
SwitchCompat是 Switch控件的向下兼容版本。
如何設置樣式?
在你的 styles.xml 文件內聲明自定義樣式。
在你的 SwitchCompat聲明里設置 android:theme的屬性值為你自定義的樣式。
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:theme="@style/MySwitch" />
Android會自動給 SwitchCompat 的 colorControlActivated 和 android:colorForeground增加 30% 的透明度。
五、Text field
允許用戶輸入文本,選擇文本(剪切,復制,粘貼),通過自動補全檢索查詢數據。
在任意的layout.xml文件內聲明你的EditText。
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hint text" />
如何設置樣式?
在你的 styles.xml文件內聲明自定義樣式。
在你的 EditText聲明里設置 android:theme的屬性值為你自定義的樣式。
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hint text"
android:theme="@style/MyEditText" />
兼容性問題
I. 在不同的Android版本里,EditText的高度和垂直對齊方式是不同的。
II. 行背景在 Android 4.0-4.4和6.0上是不透明的,而在 5.0和 5.1 上是半透明的。
Single-line text field
當輸入光標到達輸入框右邊緣時,文本框的內容會自動滾動到左邊。
要讓你的 EditText為單行,需要添加 android:singleLine屬性,並且設置其值為true。
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:hint="Hint text" />
Multi-line text field 當光標達到輸入框邊緣時,文本框會為溢出的文字自動增加一行,以使文本可以垂直滾動。
要讓你的 EditText為多行,需要添加 android:inputType屬性,並且設置其值為textMultiLine 。
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:hint="Hint text" />
Full-width text field
(和父布局等寬)適用於更深入復雜的工作。在你的 styles.xml中聲明你自定義的樣式。
在你的EditText聲明里設置 style屬性值為你自定義的樣式。
style="@style/FullWidthEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Subject" />
六、Check Box
允許用戶從一組選項中選擇多個選項。
如果你有多個選項出現在列表中,你可以通過使用 Checkboxes 代替 on/off Switches 來節省空間。
如果你只有一個選項,避免使用一個 Checkbox,但是可以使用一個 on/off switch。
在 layout.xml文件內任一位置聲明你的CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Check Box"/>
如何設置樣式?
在 styles.xml文件內聲明你的自定義樣式.
將這個樣式通過android:theme屬性應用到你的 CheckBox.
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Check Box"
android:theme="@style/MyCheckBox"/>
原文: http://www.jianshu.com/p/4bf646a627c8