只有在一个活动访问按钮,在标题栏 [英] Accessing button in title bar only in one activity

查看:134
本文介绍了只有在一个活动访问按钮,在标题栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义标题栏,而我使用的 TabHost 的布局。该 TabHost 有4个标签具有不同的活动。我添加了一个的ImageButton 的标题栏,但我只希望它在那些活动的一个活动。可能有人请告诉我该怎么做?

此外,它是确定的,如果我在标题栏中XML定义按钮?

解决方案

  myTabHost.setOnTabChangedListener(新OnTabChangeListener(){
  @覆盖
  公共无效onTabChanged(字符串tabId){
    如果(tabId ==yourTabId){
      yourButton.setVisibility(View.VISIBLE);
    }
    其他
    {
        yourButton.setVisibility(View.INVISIBLE);
    }
  }
});
 

I have a custom title bar and a TabHost layout that I'm using. The TabHost has 4 tabs with different activities. I added an ImageButton to the title bar, but I only want it active in one of those for activities. Could someone please tell me how to do that?

Also, is it ok if I define the button in the titlebar xml?

解决方案

myTabHost.setOnTabChangedListener(new OnTabChangeListener() {
  @Override
  public void onTabChanged(String tabId) {
    if (tabId =="yourTabId") {
      yourButton.setVisibility(View.VISIBLE);
    }
    else
    {
        yourButton.setVisibility(View.INVISIBLE);
    }
  }
});

这篇关于只有在一个活动访问按钮,在标题栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆