Reputation: 25
I did my homework and this question has been asked a few times, but never answered with a solution to the problem. The question is, how do you change the size of the checkbox button in a checkbox compound button?
In my case I have a checkbox with a custom button attribute pointing to a selector xml file containing items for each possible state pointing to png images. I want to be able to specify in dp the size that these images are displayed as the button for the checkbox.
The answer to this question is NOT to change the android:layout_width of the checkbox itself. Anyone know how to do this?
Also, things I've tried include adding widths and heights to the selector and items. I've tried adding my selector to a Button and resizing the button (which works for the button alone), but I can't figure out how to specify to the CheckBox that it should use that Button xml.
Upvotes: 1
Views: 3306
Reputation: 1624
I just ran into this problem myself. My checkbox has no text, and in that case this works well:
set
android:background="@my_selector_drawable"
instead of the button attribute. To avoid the standard button on top of the image, set
android:button="@null"
Now you can set the size of the checkbox with the normal android:layout_width & android:layout_height.
If you want a checkbox with text as well, this wont work
Upvotes: 1
Reputation: 25
Well for now the best I can do seems to be to build my own checkbox using a button by keeping a boolean for the state that gets inverted in the OnClickListener and calling setBackgroundResource to swap between the "checked" and "unchecked" drawables.
Meh. At least I can resize the button to be exactly what I want. Hopefully someone will come up with a better way to do it.
Upvotes: 0