java - change icon on tabhost android -
i want change icon when click on tabhost
below source code
private void settabs() { addtab("home", tabhome.class, r.drawable.home); addtab("performers", tabperformers.class, r.drawable.performers); addtab("tickets", tabtickets.class, r.drawable.tickets); addtab("info", tabinfo.class, r.drawable.info); } private void addtab(string labelid, class<?> c, int drawableid) { tabhost = gettabhost(); intent intent = new intent(this, c); tabhost.tabspec spec = tabhost.newtabspec("tab" + labelid); tabindicator = layoutinflater.from(this).inflate(r.layout.tab_indicator, gettabwidget(), false); icon = (imageview) tabindicator.findviewbyid(r.id.icon); icon.setimageresource(drawableid); spec.setindicator(tabindicator); spec.setcontent(intent); tabhost.addtab(spec); } i want change tab's icon when user press tab have used below tabhost event
tabhost.setontabchangedlistener(new ontabchangelistener() { @override public void ontabchanged(string tabid) { if (tabid.equals("tabhome")) { but not success
there tab_indicater.xml file background change not icon
below xml code
<?xml version="1.0" encoding="utf-8"?> <!-- non focused states --> <item android:drawable="@drawable/tab_unselected" android:state_focused="false" android:state_pressed="false" android:state_selected="false"/> <item android:drawable="@drawable/tab_bg_selector" android:state_focused="false" android:state_pressed="false" android:state_selected="true"/> <!-- focused states --> <item android:drawable="@drawable/tab_bg_selector" android:state_focused="true" android:state_pressed="false" android:state_selected="false"/> <item android:drawable="@drawable/tab_bg_selector" android:state_focused="true" android:state_pressed="false" android:state_selected="true"/> <!-- pressed --> <item android:drawable="@drawable/tab_bg_selector" android:state_pressed="true" android:state_selected="true"/> <item android:drawable="@drawable/tab_press" android:state_pressed="true"/> below screen shot

when click on 1 tab it's icon should change here must become orange..
can body me...
there's no straightforward way change tabspec icon. have put icons in selector drawables.
Comments
Post a Comment