Can't use android:background with button from the new material components

后端 未结 4 1896
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-18 20:52

I\'m using the new material components com.google.android.material:material with android x but I can\'t set a custom background to the button.

I know that I

4条回答
  •  萌比男神i
    2021-02-18 21:44

    The documentation for the MaterialButton class says:

    Do not use the android:background attribute. MaterialButton manages its own background drawable, and setting a new background means MaterialButton can no longer guarantee that the new attributes it introduces will function properly. If the default background is changed, MaterialButton cannot guarantee well-defined behavior.

    However, the GitHub readme says:

    Note: MaterialButton is visually different from Button and AppCompatButton. One of the main differences is that AppCompatButton has a 4dp inset on the left and right sides, whereas MaterialButton does not.

    This mentions only left/right inset, but the Attributes section of the readme shows that all four insets are supported:

    So you could add these attributes to your tag:

    android:insetTop="0dp"
    android:insetBottom="0dp"
    

提交回复
热议问题