对于一个app,很多时候我们有一个全局的按钮样式,我们是一个一个写吗?太麻烦了,其实可以一下子设置全局的。
1、修改你的colors.xml中的colorAccent
,这个是你的光标,edittext底线等等的颜色。
比如这里设置为蓝色
<color name="colorAccent">#029BD8</color>
2、设置你的主style
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:buttonStyle">@style/Widget.AppCompat.Button.Colored</item>
</style>
这里加入了
<item name="android:buttonStyle">@style/Widget.AppCompat.Button.Colored</item>
这时候只要正常使用Button,那么你的button就会是蓝色的。也会有点击效果。
或者如果只是图简单,可以直接在button上添加
style="@style/Widget.AppCompat.Button"
style="@style/Widget.AppCompat.Button.Colored"
style="@style/Widget.AppCompat.Button.Borderless"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
style="@style/Widget.AppCompat.Button"

style="@style/Widget.AppCompat.Button.Colored"

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

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

网友评论