I am having a hard time to change the text size of a switch compact thumb.
Here's my layout:
<android.support.v7.widget.SwitchCompat
android:id="@+id/switch_compat2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:checked="true"
android:switchTextAppearance="@style/MyStyle"
android:text="SwitchCompat (SDK v7+)"
app:showText="true" />
and the style:
<style name="MyStyle">
<item name="android:textColor">#229922</item>
<item name="android:textSize">10sp</item>
</style>
yet, no matter what I do on "MyStyle", the switch always look like this:
Ideally I want have it look like this:
Anyone would be willing to share their drawables to I can try to match the image above?
I am looking into these threads but not matching properly. It is making it look worse.
How to change the size of a Switch Widget
thank you!
7. textSize: textSize attribute is used to set the size of the text of a Switch. We can set the text size in sp (scale independent pixel) or dp (density pixel). Below is the example code in which we set the 25sp size for the text of a Switch.
Switch width is always twice the width of the thumb. If the thumb text width is less that the height of the track, the thumb shape will be scaled down. This can distort the shape of the thumb.
Unlike other widgets in this package, SwitchCompat is not automatically used in layouts that use the <Switch> element. Instead, you need to explicitly use <androidx.appcompat.widget.SwitchCompat> and the matching attributes in your layouts. A Switch is a two-state toggle switch widget that can be used to select one of the two available options.
androidx.appcompat.widget.SwitchCompat. SwitchCompat is a version of the Switch widget which on devices back to API v7. It does not make any attempt to use the platform provided widget on those devices which it is available normally. A Switch is a two-state toggle switch widget that can select between two options.
Actually you need to use
app:switchTextAppearance="@style/MyStyle"
Result:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With