实现Material Design风格的Button
The AppCompat Support Library 定义了几个很有用的style,这些Style是基于Widget.AppCompat.Button style实现的。当使用 AppCompat theme主题的时候,Widget.AppCompat.Button style 是默认使用到所有的button上面的。这些样式保证了Button看起来都是一样的,并且都是遵守了material design风格。
在这种情况下,最接近的颜色是粉色。
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并且根据你选择的主题应用最接近的颜色。
<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开发工程师】20-30k http://www.jianshu.com/p/8b52751360df 产品经理20-30k http://www.jianshu.com/p/cb0ac7a00796
新闻热点
疑难解答