Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increase the track length of SwitchCompat

I am having a main on/off switch for my service at the top. I would like this switch to be big and visible.
If I change the textOn attribute to be longer, it is somewhat doing what I want, but I want that to happen with a shorter textOn string length.
I tried changing thumbTextPadding and switchMinWidth and both of them didn't increase the size of the switch.
How do I change the size of SwitchCompat object?
Currently my switch object is as below :

<android.support.v7.widget.SwitchCompat
                android:id="@+id/start_service"
                style="@style/SwitchStyleCompat"
                android:text="@string/start_service_title"
                app:showText="true" />

<style name="SwitchStyleCompat">
    <item name="android:layout_width">fill_parent</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:layout_marginTop">@dimen/heading_top_margin</item>
    <item name="android:layout_marginBottom">@dimen/heading_bottom_margin</item>
    <item name="track">@drawable/abc_switch_track_mtrl_alpha</item>
    <item name="switchTextAppearance">@style/SwitchTextAppearance</item>
    <item name="android:thumb">@drawable/abc_switch_thumb_material</item>
    <item name="android:textOn">@string/switch_on</item>
    <item name="android:textOff">@string/switch_off</item>
    <item name="android:layout_alignParentLeft">true</item>
    <item name="android:layout_alignParentTop">true</item>
    <item name="android:clickable">true</item>
    <item name="android:checked">false</item>
    <item name="android:focusable">true</item>
    <item name="android:textAppearance">@style/SwitchTextFont</item>
    <item name="android:textColor">@color/text_heading_color</item>
    <item name="android:gravity">center_vertical|start</item>
    <item name="android:thumbTextPadding">25dp</item>
    <item name="android:switchMinWidth">56dp</item>
</style>
like image 720
ananth Avatar asked Dec 02 '22 15:12

ananth


1 Answers

You can increase the track length by using the material attribute app:switchMinWidth="70dp"

like image 126
Vadiraj Purohit Avatar answered Dec 29 '22 05:12

Vadiraj Purohit