Custom toggle widget in Android 4

I'm crazy on buttons in Android 4.

First of all, I set the selector as a background with two different PNG files selected from the drop-down folder:

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/form_switch_no" android:state_checked="false"/> <item android:drawable="@drawable/form_switch_ok" android:state_checked="true"/> <item android:drawable="@drawable/form_switch_no"/> </selector> 

but i don't know why they are x-scaled. I want to control this size, but I tried changing layout_width / height / weight ... without succes.

I also have a custom PNG file that will be used as a thumb switch. I also need to control the size of this thumb, because if I set the textOn and textOff properties to "", the thumb is very small. Also, I would like to change the finger overlay on the background, because it does not look centered.

Here is my definition of an XML switch:

 <Switch android:id="@+id/switchUsers" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/user" android:textOn="" android:textOff="" android:thumb="@drawable/form_switch_slider" android:track="@drawable/switch_user_selector" /> 

I tried to resize the images and make them with nine patches, but I can not achieve my goal.

Any help would be appreciated. Thanks!

+6
android
source share
1 answer

The solution for an extremely small slider without text was solved using a combination of:

 android:thumbTextPadding="25dp" android:textOn="" android:textOff="" 

Then the problem of small filling in the same slider was a problem of the image with 9 patches. I had to extend the bottom and right black lines with another pixel.

Hope this helps someone with the same issue.

+8
source share

All Articles