Solution to compatibility problem of Android setbuttondrawable()

Solution to compatibility problem of Android setbuttondrawable()

Compatibility issue with setbuttondrawable()

Api16 implementation

Api23 implementation

conclusion

RadioButton and Check@R_ 762_ 2419 @ are commonly used widgets in Android apps. They are derived from the compoundbutton and allow users to set the background and button styles by themselves. However, sometimes we just want to simply set a stateful background and hide its default style. However, when we call setbuttondrrawable (null) or setbuttondrrawable (0), we find that it has no effect at all. Originally, the code implementation of setbuttondrrawable of composundbutton shields the drawable with null or resid 0, forcing us to pass in a valid drawable object.

At this point, transparent colors can come in handy:

button.setButtonDrawable(new ColorDrawable(Color.TRANSPARENT));

reference resources:

Hide RadioButton, Check@R_ 762_ 2419 @ picture setbuttondrawable:

RadioButton and Check@R_ 762_ 2419 @ are commonly used widgets in Android apps. They are derived from the compoundbutton and allow users to set the background and button styles by themselves. However, sometimes we just want to simply set a stateful background and hide its default style. However, when we call setbuttondrrawable (null) or setbuttondrrawable (0), we find that it has no effect at all. Originally, the code implementation of setbuttondrrawable of composundbutton shields the drawable with null or resid 0, forcing us to pass in a valid drawable object.

At this point, transparent colors can come in handy:

Thank you for reading, hope to help you, thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>