android - How to style disabled state for tabwidget button preferably using xml -
i having following problem. want add special image tabbuton disabled state it's not working. doing in selector.
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/active" android:state_pressed="true"/> <item android:drawable="@drawable/unactive" android:state_selected=true"/> <item android:drawable="@drawable/disabled" android:state_enabled="false"/> <item android:drawable="@drawable/unactive"/> </selector>
this same selector single "standalone" button, it's not working, it's showing disabled state when button enabled. doing wrong?
edit: @nightcrawler sugestions found out optimal selector active unactive state, still can't make state_enabled="false" show diffrent state when button disabled...
<item android:drawable="@drawable/active" android:state_selected="true"/> <item android:drawable="@drawable/unactive" android:state_selected="false"/> <item android:drawable="@drawable/disabled" android:state_enabled="false"/> <item android:drawable="@drawable/unactive"/>
workaround: went on implement image change disabled state in code with:
tabwidget.getchildat(4).setenabled(true); icon = (imageview) wrapper.tabwidget.getchildat(4).findviewbyid(r.id.icon); icon.setimageresource(r.drawable.enabled) tabwidget.getchildat(4).setenabled(false); icon = (imageview) wrapper.tabwidget.getchildat(4).findviewbyid(r.id.icon); icon.setimageresource(r.drawable.disabled)
this work ok still know possible define disabled state button in tabwidget using xml.
findings: after more tinkering found out why disabled state not registered. in case using custom layouts buttons, customizing tabhost , going have sort of image in layout. drawable states defined above applied image in layout , not whole layout. selector enough have 3 desired states:
<item android:drawable="@drawable/menu_network_active" android:state_selected="true"/> <item android:drawable="@drawable/menu_network_offline" android:state_enabled="false"/> <item android:drawable="@drawable/menu_network_unactive"/>
but when disable tabwidget button have manually set image using in disabled this:
wrapper.tabwidget.getchildat(0).setenabled(false); icon = (imageview) wrapper.tabwidget.getchildat(0).findviewbyid(r.id.icon); icon.setenabled(false);
in case disabled selector state triggered on image , desired background shown.
still not explained:
only thing left missing in puzzle why selected state of image being triggered when tabbutton selected not disabled state. tried setting listeners on "icon" see if maybe called when change tab not happening , still image in selector set selected. selected triggered (somehow) on image in layout disabled not , have no idea why. if looking @ question has findings please add comment or answer feature reference. looking solve similar bug read wokraround or findings parts these solve you.
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <!-- non focused states --> <item android:drawable="@drawable/footer" android:state_focused="false" android:state_pressed="false" android:state_selected="false"/> <item android:drawable="@drawable/footer_pressed" android:state_focused="false" android:state_pressed="false" android:state_selected="true"/> <!-- pressed --> <item android:drawable="@drawable/footer_pressed" android:state_pressed="true" android:state_selected="true"/> <item android:drawable="@drawable/footer_pressed" android:state_pressed="true"/> </selector>`enter code here`
Comments
Post a Comment