This is my final decision.
In the layout:
<ToggleButton android:id="@+id/mailbox:toggle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:background="@drawable/toggle_drawable_layers"/>
in toggle_drawable_layers.xml file
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:drawable="@drawable/toggle_drawable_bkg"></item> <item android:left="10dp" android:drawable="@drawable/toggle_drawable_left" android:gravity="center_vertical|center_horizontal" /> </layer-list>
in toggle_drawable_left.xml file
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true"> <bitmap android:src="@drawable/bitmap_checked" android:gravity="center_vertical|center_horizontal" /> </item> <item android:state_checked="false"> <bitmap android:src="@drawable/bitmap_unchecked" android:gravity="center_vertical|center_horizontal" /> </item> </selector>
source share