[英]wrong Button textColor and drawablePadding on pre-Lollipop using Appcompat
I have wrong button style on pre-Lollipop devices. 我在Lollipop之前的设备上有错误的按钮样式。
compiling using appcompat library. 使用appcompat库进行编译。
compile 'com.android.support:appcompat-v7:23.0.1'
编译'com.android.support:appcompat-v7:23.0.1'
values/styles.xml 价值观/ styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@android:color/holo_orange_light</item>
<item name="colorPrimaryDark">@android:color/holo_orange_dark</item>
<item name="colorAccent">@android:color/holo_green_light</item>
<item name="colorControlNormal">@android:color/holo_purple</item>
<item name="colorControlHighlight">@android:color/holo_red_light</item>
<item name="colorButtonNormal">@android:color/holo_green_light</item>
<item name="android:buttonStyle">@style/ButtonTheme</item>
</style>
<style name="ButtonTheme" parent="android:Widget.Button">
<item name="android:textColor">@android:color/white</item>
<item name="android:textAllCaps">true</item>
<item name="android:drawablePadding">10dp</item>
<item name="android:padding">10dp</item>
</style>
v21/styles.xml V21 / styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="ButtonTheme" parent="android:Widget.Material.Button">
<item name="android:textColor">@android:color/white</item>
<item name="android:textAllCaps">true</item>
<item name="android:drawablePadding">10dp</item>
<item name="android:padding">10dp</item>
</style>
</resources>
The result is http://prntscr.com/8mt1jx 结果是http://prntscr.com/8mt1jx
"New button" adding by xml on ISC has no style textColor and drawablePadding. 在ISC上添加xml的“新按钮”没有样式textColor和drawablePadding。 Do you have any ideas to correct it?
你有什么想法来改正吗?
The problem is the buttonStyle
in your normal styles.xml. 问题是普通styles.xml中的
buttonStyle
。
Replace 更换
<item name="android:buttonStyle">@style/ButtonTheme</item>
With 同
<item name="buttonStyle">@style/ButtonTheme</item>
And it should work. 它应该工作。
So for pre-Lollipop devices work this: 因此,对于预制Lollipop设备,请执行以下操作:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@android:color/holo_orange_light</item>
<item name="colorPrimaryDark">@android:color/holo_orange_dark</item>
<item name="colorAccent">@android:color/holo_green_light</item>
<item name="colorControlNormal">@android:color/holo_purple</item>
<item name="colorControlHighlight">@android:color/holo_red_light</item>
<item name="colorButtonNormal">@android:color/holo_green_light</item>
<item name="buttonStyle">@style/ButtonTheme</item>
<item name="android:buttonStyle">@style/ButtonProgramAddTheme</item>
</style>
<style name="ButtonTheme" parent="Widget.AppCompat.Button">
<item name="android:textColor">@android:color/white</item>
<item name="android:textAllCaps">true</item>
<item name="android:drawablePadding">10dp</item>
<item name="android:padding">10dp</item>
</style>
<style name="ButtonProgramAddTheme" parent="android:Widget.Button">
<item name="android:textColor">@android:color/white</item>
<item name="android:textAllCaps">true</item>
<item name="android:drawablePadding">10dp</item>
<item name="android:padding">10dp</item>
</style>
The result is: http://prntscr.com/8mtoqa 结果是: http : //prntscr.com/8mtoqa
Also for the same view of the program add buttons we can add custom background by selector, because AppCompat does not in fact support the Button widget on pre-Lollipop devices. 同样对于程序添加按钮的相同视图,我们可以通过选择器添加自定义背景,因为AppCompat实际上不支持Lollipop前设备上的Button小部件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.