<item name="android:width",Android 5.0 M特性 樣式設置

修改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

一個在按下的時候會展現墨水散開的效果但沒有凸起效果由墨水形成的按鈕。

e88c9854ea6224a9c349237fd35a4fc4.png

在layout.xml內的任意位置聲明你的 Button並設置 Borderless樣式.

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Button"

style="@style/Widget.AppCompat.Button.Borderless"/>

如何設置樣式?

c49aa49762eb9663605a93faa370886e.png

在你的 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 按鈕在手指抬起和按下的時候會展現墨水在紙上散開的效果。

106641dd46399ce3eed86ea7636aa172.png

在layout.xml內的任意位置聲明你的 Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Button"/>

如何設置樣式?

ed01b2392603962377c71ba8b2f01656.png

在你的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

36c43907105b37531d563f99989d138f.png

在layout.xml文件內任意位置聲明你的RadioButton

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:checked="true"

android:text="Radio Button"/>

如何設置樣式?

d68d32a8efa1b7da1b7506e6e5cf4de2.png

在 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” 的做法已被棄用。請用文首所示圖例來代替。

3e334744f87867721cb939336ec005ac.png

在任意的layout.xml文件內聲明你的SwitchCompat 。

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:checked="true" />

SwitchCompat是 Switch控件的向下兼容版本。

如何設置樣式?

7821ec011ccbf775b7b6422c26dc493a.png

在你的 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" />

如何設置樣式?

c504733d6d78bb6190d79df321dc9fc4.png

在你的 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。

3f84e3ca80456588da9a06afc348390a.png

在 layout.xml文件內任一位置聲明你的CheckBox

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:checked="true"

android:text="Check Box"/>

如何設置樣式?

a10acffc891c29f62db4c8b6e4ce6518.png

在 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值