Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't change the textsize of the thumb of SwitchCompat widget

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:

enter image description here

Ideally I want have it look like this:

enter image description here

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!

like image 480
gmmo Avatar asked Apr 01 '16 19:04

gmmo


People also ask

How to set the size of the text of a switch?

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.

Why is the thumb text size of switchswitch scaled down?

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.

How do I use the switchcompat widget in my layout?

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.

What is switchcompat androidx?

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.


1 Answers

Actually you need to use

app:switchTextAppearance="@style/MyStyle"

Result:

enter image description here

like image 106
Bharatesh Avatar answered Nov 05 '22 22:11

Bharatesh