Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Jetpack compose Switch Padding

Is there an easy way to remove the switch’s internal padding in compose?

I tried supplying a 0.dp in its modifier but it doesn’t get rid of the internal paddings

 Switch(
      modifier = Modifier
           .padding(0.dp)
           .background(Color.Red), // just to show the internal box paddding
      checked = true,
      onCheckedChange = { }
 )

Switch

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thank you in advance.

>Solution :

Composables such as Switch, CheckBox, RadioButton, Button, Slider and others i can’t recall at the moment have minimum 48.dp size because of minimum touch target for accessibility.

You can remove it with CompositionLocalProvider

CompositionLocalProvider(LocalMinimumTouchTargetEnforcement provides false) {
    Switch(
        modifier = Modifier
            .padding(0.dp)
            .background(Color.Red), 
        checked = true,
        onCheckedChange = { }
    )
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading