Removing padding from toggle button in Android -


i creating simple toggle button in android , setting background drawable.

<togglebutton     android:layout_width="wrap_content"     android:drawablepadding="0dp"     android:layout_height="wrap_content"     android:text=""     android:textsize="12sp"     android:padding="0dp"     android:id="@+id/tag_text"     android:background="@drawable/toggle_selector"/> 

toggle_selector.xml looks this:

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

toggle_button_off , toggle_button_on have simple shape drawable color.

and how inflating toggle button view:

view child = getlayoutinflater().inflate(r.layout.tags, null);         togglebutton tag = ((togglebutton)child.findviewbyid(r.id.tag_text));         tag.settext("testing");         tag.settextoff("testing");         tag.settexton("testing");         flowlayout.addview(child); 

the problem there padding around text in toggle button , not able rid of setting padding = "0dp". text on these buttons dynamically added setting constant height weight not helping too.

enter image description here

i got solution setting minwidth, minheight 0dp. wrapping content in width , height. , adding custom padding togglebutton want.

<togglebutton     android:layout_width="wrap_content"     android:minwidth="0dp"     android:minheight="0dp"     android:layout_height="wrap_content"     android:text=""     android:textsize="12sp"     android:padding="2dp"     android:id="@+id/tag_text"     android:background="@drawable/toggle_selector"/>