Pregunta

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.

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);

and the XML file:

<?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>

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

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

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

mTabHost.getTabWidget().setStripEnabled(false);

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.

¿Fue útil?

Solución

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. :)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top