Android API 21 changes my custom button background

ぐ巨炮叔叔 提交于 2019-12-08 15:20:37

Material buttons have a default stateListAnimator that provides state-based elevation (e.g. 0dp when disabled, 1dp when enabled). You can clear it by setting android:stateListAnimator="@null" in your style or directly on the Button.

Here is what that would look like on your button XML:

<Button android:id="@+id/sm_achievements_btn"
    ...
    android:textAllCaps="false"
    android:stateListAnimator="@null" />

Also, you're using the wrong parent for your button style. You should never set a theme as the parent for a widget style. Regardless, here is what that should look like if you prefer that route:

<Button android:id="@+id/sm_achievements_btn"
    ...
    style="@style/MyButtonStyle" />

<style name="MyButtonStyle" parent="android:Widget.Material.Light.Button">
    <item name="android:textAllCaps">false</item>
    <item name="android:stateListAnimator">@null</item>
</style>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!