FragmentTabHost TabWidget标签栏不能自定义 [英] FragmentTabHost TabWidget tabStrip cannot be customized

查看:227
本文介绍了FragmentTabHost TabWidget标签栏不能自定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是真的困惑了我,因为每当我把我的FragmentTabHost的StripEnabled它不这样做,我想它是的方式。

This was really confusing for me since whenever I set the StripEnabled of my FragmentTabHost it doesn't do the way I wanted it to be.

要在这里开始是code为FragmentTabHost:

To begin here is the code for FragmentTabHost:

mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
        mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);

        Bundle b = new Bundle();

        b.putString("0", "tab1");
        mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator(null,getResources().getDrawable(R.drawable.selector_tab1)),
                Fragment1.class, b);

        b = new Bundle();
        b.putString("1", "tab2");
        mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator(null, getResources().getDrawable(R.drawable.selector_tab2)),
                Fragment2.class, b);

和XML文件:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <FrameLayout
        android:id="@+id/realtabcontent"
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        />

    <android.support.v4.app.FragmentTabHost
        android:id="@android:id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_weight="0"/>
    </android.support.v4.app.FragmentTabHost>

</LinearLayout>

现在,当我添加这些行codeS它工作得很好:

Now when I add these line of codes it works just fine:

mTabHost.getTabWidget().setShowDividers(LinearLayout.SHOW_DIVIDER_NONE);

它成功地隐藏选项卡上的所有分频器但是当我使用这条线code的禁用标签栏:

It successfully hides all the dividers on the tab but when I use this line of code to disable tabstrip:

mTabHost.getTabWidget().setStripEnabled(false);

标签栏仍然在那里,但是当我把它设置为true,未选中的物品带变成灰色,我真的不能告诉为什么。

the tabStrip is still in there, but when I set it to true the strip for unselected items turns into gray and I can't really tell why.

好了,我在这里的主要目的是改变标签栏的颜色或以其他方式完全删除,但这个问题我真的不能肯定,我应该怎么做。我试图用一个膨胀的看法,但因此如果选择与否的标签我不能再告诉选择不工作了。希望有人能帮助我在此我如何可以改变它。但我真的希望有人能帮助我如何改变颜色条,因为这变得很烦人。

Well, my main objective here is to change the color of that tabStrip or otherwise remove it totally but with this problem I can't really be sure on how I should do it. I tried using an inflated view but the selector doesn't work anymore so I can't tell anymore if the tab is selected or not. Hope someone can help me on this on how I can change it. But I really hope someone can help me on how to change the strip color since this becomes really annoying.

推荐答案

我已经用一个选择改变背景资源改变了它。我用了9片图像,以确保一切适合。这里是将所有的选项卡后,code:

I already changed it by changing the background resource with a selector. I used a 9 patch image to make sure everything will fit. here's the code after adding all the tabs:

tabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.tab_selector);

只是把它所有的孩子的和它的作品。虽然没有一个是最好的解决方案解决了我的问题。 :)

just to it for all childs and it works. Not a best solution though it solves my problem. :)

这篇关于FragmentTabHost TabWidget标签栏不能自定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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