开发者

How to change the icon of tab host once setup? (Android)

开发者 https://www.devze.com 2023-01-03 08:32 出处:网络
I am trying to change the Icon of one of the tabs of tab host at run time. I am not able to figure out hwo to do with the widget. could

I am trying to change the Icon of one of the tabs of tab host at run time. I am not able to figure out hwo to do with the widget. could some one let me know how its 开发者_如何学Cdone ?

 spec = tabHost.newTabSpec("hello").setIndicator("hello",
       res.getDrawable(R.drawable.tab1)).setContent(intent);
 tabHost.addTab(spec)

The xml file is as below selector xmlns:android="http://schemas.android.com/apk/res/android" -- When selected, use grey -- item android:drawable="@drawable/icon1" android:state_selected="true" /> -- When not selected, use white- item android:drawable="@drawable/icon1" /selector

Thanks , Titus


Here is how to change the icon after the TabHost (tab child) was created. This solution is not using the XML selector, this code will change the icon permanently.

View ic = (View) tabHost.getTabWidget().getChildTabViewAt(0).findViewById(android.R.id.icon);
ic.setBackgroundResource(R.drawable.icon_public);

This example will change the icon of first tab.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号