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

Material 3 MaterialSwitch size is too large by default? How to make it smaller?

I’m using the code below to create a material 3 switch in Android using XML, and it’s much larger than a normal switch. Is there any way to make it smaller?

<com.google.android.material.materialswitch.MaterialSwitch   
   android:id="@+id/biometrics_switch"   
   style="@style/Widget.Material3.CompoundButton.MaterialSwitch"   
   android:layout_width="wrap_content"   
   android:layout_height="wrap_content"   
   app:layout_constraintEnd_toEndOf="parent"   
   app:layout_constraintTop_toTopOf="parent"   
   app:switchPadding="@dimen/_10sdp" android:minHeight="@dimen/_10sdp" 
   app:thumbTint="@color/white" app:trackTint="@color/neutral_800" />

>Solution :

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

In Material Switch width and height affect on clickable area for switch
you should use scaleX and scaleY to change the size of it.
Also In jetpack compose you should use Modifier.scale()

This is a sample code for it:

<com.google.android.material.materialswitch.MaterialSwitch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleX="0.8"
android:scaleY="0.8"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
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