Android Emulator checkbox and radio button bug - various incorrect states are showed on ui

Viewed 37

Recently I've spotted weird emulator behaviour with showing the radio buttons and checkboxes. Instead of having only 2 states of UI it has or to be more specific it shows 4 different or even more. I suppose they are frozen animation states. On the layout inspector and on the newer version of the API it looks normal. See the pictures below:

checkboxes on the emulator checkboxes on the layout inspector

I spotted it at Api versions: 23 and 24. And on 28 and 30 it behaves correctly.

So the question is: is it really a problem of the emulator and it won't happen on real devices? Or maybe it is a matter of some settings?

Edit: It is happening not only on emulators.

1 Answers

I've found the reason for such incorrect states of compound buttons. It's is because I've used an Inset to add left padding before the button like that:

fun CompoundButton.addButtonDrawableInsets(insetDp: Int) {
    val originalDrawable = buttonDrawable ?: return
    buttonDrawable = InsetDrawable(originalDrawable, dp(insetDp))
}

I tried to find a way to add padding differently but I've ended up wrapping every button with additional FrameLayout and adding padding there. Watch out with RadioGroup because if it doesn't have a direct child as RadioButton then its functionality breaks and you have to implement reselecting previous buttons by yourself.

Related