【问题标题】:TabHost.TabSpec setIndicatorTabHost.TabSpec setIndicator
【发布时间】:2013-07-26 13:29:15
【问题描述】:

我想摆脱默认指示器以在选择选项卡时获得相同的结果(无指示器)。我试过了:

TabHost.TabSpec specs = tabHost.newTabSpec("").setIndicator("").setContent(intent);
TabHost.TabSpec specs = tabHost.newTabSpec("").setIndicator("",null).setContent(intent);

但是这些都不起作用。如何删除该指标?
感谢您的宝贵时间。

【问题讨论】:

    标签: android android-tabhost tabactivity android-tabactivity


    【解决方案1】:
            TabHost  tabHost = getTabHost();
    
            TabSpec spec;
    
            Intent intent;
    
            //Home Tab
            View view1 = LayoutInflater.from(MainActivity.this).inflate(R.layout.home, null);
    
            intent = new Intent(MainActivity.this, Firstclass.class);
    
            spec = tabHost.newTabSpec("HOME").setIndicator(view1)
                    .setContent(intent);
    
            tabHost.addTab(spec);
    

    这样你就可以摆脱它了...

    【讨论】:

    • 嘿,Nepster,你能解释一下你在这里做了什么吗?我有一个类似的问题,我得到的唯一答案是指用 XML 做这件事的一种方式,但我有点“喜欢”以编程方式执行它,这似乎就是这种方式,只是我并没有真正了解您所做的一切,特别是因为我没有访问“getTabHost()”方法的权限。
    • 现在已弃用为什么不使用最新的maxalley.wordpress.com/2013/05/18/… 但如果您仍然想了解这一点,我已经为每个 view1 创建了单独的类,在 view1 中膨胀我的主屏幕,然后我就这样做了对于所有其他选项卡并像我在主页选项卡中一样添加它们。
    • 非常感谢您的链接,我一直在寻找未被弃用的东西,但我找不到太多...现在就进入文档。干杯人!
    【解决方案2】:

    删除他的,试试这个:

    TabHost.TabSpec specs = tabHost.newTabSpec("").setContent(intent);
    TabHost.TabSpec specs = tabHost.newTabSpec("").setContent(intent);
    

    【讨论】:

      【解决方案3】:
       private void addTab(String labelId, int drawableId, Class<?> c) {
          Intent intent = new Intent(this, c);
          tabHost = getTabHost();     
          TabHost.TabSpec spec = tabHost.newTabSpec(labelId);
          icon.setImageResource(drawableId);
          spec.setContent(intent);
          tabHost.addTab(spec);
      }
      

      【讨论】:

        【解决方案4】:
        private static void addTab(TabMainActivity activity, TabHost tabHost,TabHost.TabSpec tabSpec, TabInfo tabInfo) 
        {
            Drawable indicator = mContext .getResources().getDrawable( R.drawable.red_box );
            tabSpec.setIndicator(tag,indicator);
            tabHost.addTab(tabSpec);
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多