开发者

How do I hide a tab in a TabActivity?

开发者 https://www.devze.com 2022-12-26 18:40 出处:网络
开发者_Python百科I have created three tabs in TabActivity onCreate. How can I hide one tab at runtime?To hide the tab you must remove it from the TabWidget. Just setting INVISIBLE is not enough. So,

开发者_Python百科I have created three tabs in TabActivity onCreate.

How can I hide one tab at runtime?


To hide the tab you must remove it from the TabWidget. Just setting INVISIBLE is not enough. So, to hide the tab:

tab = getTabHost().getTabWidget().getChildTabViewAt(tabPosition);
getTabHost().getTabWidget().removeViewAt(tabPosition);

And to show that tab again:

getTabHost().getTabWidget().addView(tab, tabPosition);


For Removing the particular tab from tabwidget :

tab = tabhost.getTabWidget().getChildTabViewAt(tabPosition); tabhost.getTabWidget().removeView(tab);

and for adding it back to tabwidget :

 tabhost.getTabWidget().addView(tab);

OR

 tabhost.getTabWidget().addView(tab,tabPosition);


If you want to hide the tabWidget you can do so by setting the visibility to GONE/INVISIBLE like:

getTabWidget().setVisibility(TabWidget.GONE);   
0

精彩评论

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

关注公众号