2

FragmentTabHost の StripEnabled を設定するたびに、希望どおりに動作しないため、これは本当に混乱しました。

まず、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>

これらのコード行を追加すると、問題なく動作します。

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

タブのすべての仕切りを正常に非表示にしますが、このコード行を使用してタブストリップを無効にすると:

mTabHost.getTabWidget().setStripEnabled(false);

tabStrip はまだそこにありますが、true に設定すると、選択されていない項目のストリップが灰色になり、その理由がわかりません。

さて、ここでの私の主な目的は、そのタブストリップの色を変更するか、それ以外の場合は完全に削除することですが、この問題により、どうすればよいか確信が持てません。膨張したビューを使用してみましたが、セレクターが機能しなくなったため、タブが選択されているかどうかわかりません。どうすれば変更できるかについて、誰かが私を助けてくれることを願っています。しかし、これは本当に面倒なので、誰かがストリップの色を変更する方法について私を助けてくれることを本当に願っています.

4

1 に答える 1