實現(xiàn)Material Design風(fēng)格的Button
The AppCompat Support Library 定義了幾個很有用的style,這些Style是基于Widget.AppCompat.Button style實現(xiàn)的。當(dāng)使用 AppCompat theme主題的時候,Widget.AppCompat.Button style 是默認使用到所有的button上面的。這些樣式保證了Button看起來都是一樣的,并且都是遵守了material design風(fēng)格。
在這種情況下,最接近的顏色是粉色。

Simple Button: @style/Widget.AppCompat.Button
<Button style="@style/Widget.AppCompat.Button" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="16dp" android:text="@string/simple_button"/>
Colored Button: @style/Widget.AppCompat.Button.Colored The Widget.AppCompat.Button.Colored 繼承了 Widget.AppCompat.Button style并且根據(jù)你選擇的主題應(yīng)用最接近的顏色。
<Button style="@style/Widget.AppCompat.Button.Colored" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="16dp" android:text="@string/colored_button"/>如果你想定制背景顏色,你可以定制一個主題,使用android:theme這個屬性,繼承自ThemeOverlay主題。
<Button style="@style/Widget.AppCompat.Button.Colored" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="16dp" android:theme="@style/MyButtonTheme"/> defining the following theme: <!-- res/values/themes.xml --> <style name="MyButtonTheme" parent="ThemeOverlay.AppCompat.Light"> <item name="colorAccent">@color/my_color</item> </style>

普照天星【java開發(fā)工程師】20-30k http://www.jianshu.com/p/8b52751360df 產(chǎn)品經(jīng)理20-30k http://www.jianshu.com/p/cb0ac7a00796


新聞熱點
疑難解答