一身转战三千里,一剑曾百万师。这篇文章主要讲述Android 更改按钮样式 Button Styles相关的知识,希望能为你提供帮助。
extends:http://stackoverflow.com/questions/26346727/android-material-design-button-styles
I will add my answer since I don‘t use any of the other answers provided. With the Support Library v7, all the styles are actually already defined and ready to use, for the standard buttons, all of these styles are available:
Widget.AppCompat.Button :
文章图片 Widget.AppCompat.Button.Colored :
文章图片 Widget.AppCompat.Button.Borderless
文章图片 Widget.AppCompat.Button.Borderless.Colored :
文章图片 |
How to change the colorFor the whole app:
The color of all the UI controls (not only buttons, but also floating action buttons, checkboxes etc.) is managed by the attribute
colorAccent
as explained
here. You can modify this style and apply your own color in your theme definition:< style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> ... < item name="colorAccent"> @color/Orange< /item> < /style>
For a specific button:
If you need to change the style of a specific button, you can define a new style, inheriting one of the parent styles described above. In the example below I just changed the background and font colors:
< style name="AppTheme.Button" parent="Widget.AppCompat.Button.Colored"> < item name="colorButtonNormal"> @color/Red< /item> < item name="android:textColor"> @color/White< /item> < /style>
Then you just need to apply this new style on the button with:
android:theme="@style/AppTheme.Button"
To set a default button design in a layout, add this line to the styles.xml theme:
< item name="buttonStyle"> @style/btn< /item>
【Android 更改按钮样式 Button Styles】where
@style/btn
is your
button
theme. This sets the
button
style for all the buttons in a layout with a specific theme推荐阅读
- SELinuxSEAndroidMACAndorid(AOSP) seplicy 相关资料
- Android消息机制1-Handler(Java层)(转)
- Android学习路线
- 系统去掉 Android 4.4.2 的StatusBar和NavigationBar
- Android添加全屏启动画面
- Android开发系列(二十一)(Spinner的功能和使用方法以及实现列表选择框)
- EventBus在Android中的简单使用
- Unity3D Android手机屏幕分辨率问题
- Android应用程序无法读写USB设备的解决方法