开发者

How Do I change the indicator of a tabhost dynmaicly from an other activity

I have a tabhost that contains 5 tab开发者_Python百科 (Monday .... Friday). I want to change the indicators dynamically from other activities (using a button) Does any one have a solution Thanks in advance


I think you couldn't do this in directly. Instead try to store the configuration of you tab host somewhere. So when you came pack you tab activity and hit the onResume() method you can react on the changed tab configuration and rearrange the tabs.

The location where you store the tab configuration depends on whether the configuration should survive the restart of the whole application. When you don't care that the application is restarted with the standard configuration you could use a Application class to store this information. If the tab changed configuration should also be available after an restart, you will have to persist it somehow on the device. You can read about the different options you got on the Android developer page.


Get a hold of the tabIndicator View. It usually consists of an ImageView and a TextView unless you have your own custom TabIndicator.

ViewGroup tabInidcator = tabHost.getTabWidget().getChildTabViewAt('the index of tab you want to change')

The textView inside the relative layout is currently the 2nd child (careful this might change) unless you have a custom tabIndicator view.

TextView tabIndicator = (TextView) tabIndicator.getChildAt(1);
indicator.setText("thunday");

If you want to change the image get the imageView at location 0

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜