android - 9-patch background adds top and bottom padding. How to avoid it? -


i'm trying customize togglebutton in app. i'm setting 9-patch image background written here. , in layout xml:

<togglebutton     android:id="@+id/toggle"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_gravity="center_horizontal"     android:background="@drawable/btn_toggle_bg"     android:checked="true"     android:gravity="center_horizontal|center_vertical" /> 

btn_toogle_bg.xml:

<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >     <item         android:id="@+android:id/background"         android:drawable="@android:color/transparent"/>     <item         android:id="@+android:id/toggle"         android:drawable="@drawable/btn_toggle"/> </layer-list> 

btn_toggle.xml:

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

9-patch looks (btn_toggle_off):

btn_toggle_off

the same image checked state.

but when i'm applying background unexpected top , bottom padding:

enter image description hereenter image description here

i've got same result when applying background button or using xml-drawable background. how avoid unexpected padding? help, please.


update:

also, when i'm adding style app theme there no padding togglebutton becames unclickable (doesn't change state):

styles.xml:

<style name="widget.button.toggle" parent="android:widget">     <item name="android:background">@drawable/btn_toggle_bg</item>     <item name="android:disabledalpha">?android:attr/disabledalpha</item> </style> 

themes.xml:

<style name="mythemename" parent="@android:theme.black">     <item name="android:buttonstyletoggle">@style/widget.button.toggle</item> </style> 

it seems needed extend android:widget.button.toggle style:

<style name="widget.button.toggle" parent="android:widget.button.toggle">     <item name="android:background">@drawable/btn_toggle_bg</item>     <item name="android:disabledalpha">?android:attr/disabledalpha</item> </style> 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -