Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to change the spacing around MaterialCheckBox?

I'm curious to know whether it's possible to change the default spacing that's placed around MaterialCheckBox... or whether there are plans to allow for this.

Let's say, for the sake of example, I have a CheckBox defined with four TextViews around it (to the left, right, top and bottom of it) and I specify no margins on any of the five Views. If I define my app's theme as Theme.AppCompat.Light then this CheckBox is rendered with equal spacing around it as follows:

CheckBox as rendered in Theme.AppCompat.Light theme

If I change the app's theme to Theme.MaterialComponents.Light and make no other changes to the app then the CheckBox is rendered as follows:

enter image description here

Note the unequal spacing which I would like to customise on a per-need basis. There's nothing mentioned in the MaterialCheckBox documentation and I can't see anything obvious in the class definition about being able to change this spacing.

(For what it's worth I'm using the latest version of the com.google.android.material:material library, i.e. 1.1.0-alpha03. And everything I've said above holds regardless of whether I define a CheckBox, AppCompatCheckBox or MaterialCheckBox in my layout. The key thing is changing the theme from Theme.AppCompat.Light to Theme.MaterialComponents.Light.)

like image 252
Adil Hussain Avatar asked Feb 16 '19 15:02

Adil Hussain


1 Answers

This looks related to MaterialCheckBox enforcing a 48dp minTouchTargetSize for accessibility using android:minWidth in the CheckBox style (this should be added to the documentation). Setting android:minWidth to 0dp should work.

like image 185
user10740614 Avatar answered Nov 06 '22 23:11

user10740614