简体   繁体   English

使用Appcompat在前棒棒糖上使用错误的按钮textColor和drawablePadding

[英]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.

相关问题 使用 appcompat 时设置 RecyclerView 边缘发光预棒棒糖 - Set RecyclerView edge glow pre-lollipop when using appcompat 通过AppCompat在可棒棒糖上的可绘制对象中使用colorPrimary - Use colorPrimary in drawable on pre-lollipop with AppCompat 带有AppCompatTheme的预棒棒糖设备上的颜色错误 - Wrong colors on pre-lollipop devices with AppCompatTheme FAB在棒棒糖上的位置错误 - Wrong FAB position on Pre-Lollipop 在Android中使用appcompat小部件时,棒棒糖播放器之前的设备中的默认字体 - Default font in pre-lollipop devices when using appcompat widgets in Android 无法理解如何使用Theme.AppCompat为前Lollipop设备设置Android应用程序样式 - Can't understand how to style Android app for pre-Lollipop devices using Theme.AppCompat Android AppCompat SearchView EditText 在预棒棒糖上缺少底线 - Android AppCompat SearchView EditText missing bottom line on pre-lollipop Appcompat v21工具栏提升前棒棒糖 - Appcompat v21 Toolbar elevation pre-lollipop 前棒棒糖的无边框按钮与支持图书馆 - Borderless Button on Pre-Lollipop with Support Library 浮动按钮在Pre-lollipop版本中不起作用 - Floating button not working in Pre-lollipop version
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM