AppCompat按钮:背景始终为白色,适用于API< 21

时间:2017-10-22 06:53:16

标签: android button android-appcompat

我在我的应用程序中使用Material designs主题,并且API没有问题等于21。 但是使用API​​< 21我有一些无法解决的关键问题。

对于API< 21我使用AppCompat Theme来获得Material Theme效果。

让我们看一下Button示例:

<ImageButton
        android:id="@+id/buttonShare"

        android:layout_width="match_parent"
        android:layout_height="60dp"

        android:layout_alignParentBottom="true"

        android:src="@drawable/share"       
        android:theme="@style/StandartButton"
        style="@style/Widget.AppCompat.Button.Colored"  
        />

和style.xml文件:

    <style name="AppBaseTheme" parent="Theme.AppCompat.Light">
        <item name="android:buttonStyle">@style/StandartButton</item>
    </style>

    <style name="StandartButton" parent="ThemeOverlay.AppCompat">   
        <item name="colorButtonNormal">@color/blue</item>               
    </style>

结果:

enter image description here

我没有使用正确的屏幕截图添加styles-v21,因为它使用几乎相同的代码正常工作。

那么任何想法如何解决旧API的问题?

1 个答案:

答案 0 :(得分:0)

我找不到使用样式的正确解决方案(可能是它的AppCompat错误),这就是找到解决方法的原因。

使用按钮添加layout-v21文件夹会引用带有“材质主题”的样式。 并在当前background文件夹中设置layout

请注意,它只能是临时修复。