简体   繁体   English

如何在Android屏幕中禁用选项卡?

[英]how to disable a tab in android screen?

你好,你能告诉我如何禁用Android代码的UI中的选项卡..(eclair代码)

If you mean to disable one tab button on TabWidget, then try this code: 如果您要禁用TabWidget上的一个标签按钮,请尝试以下代码:

// tabHost = ... (get TabHost)
tabHost.getTabWidget().getChildTabViewAt(your_index).setEnabled(false);

If you want to disable tab widget in overall, then: 如果要整体禁用选项卡小部件,则:

// tabWidget = ... (get TabWidget)    
tabWidget.setEnabled(false);

Read SDK Help for references: 阅读SDK帮助以获取参考:

Extend TabHost and override methods: 扩展TabHost并覆盖方法:

@Override
public void setCurrentTab(int currentTab) {
    if (currentTab != 2)  // position of the tab that should not get selected
        super.setCurrentTab(currentTab);
    else
        // in my case I want to trigger something here but I don't want the button to get selected
}

@Override
public void setCurrentTabByTag(String tag) {
    if (!"\"plus_tab\"".equals(tag))  // tag of the tab that should not get selected
        super.setCurrentTabByTag(tag);
    else
        // in my case I want to trigger something here but I don't want the button to get selected
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM