32

これが私が削除したいものです:

ここに画像の説明を入力してください

現在表示されているタブとタブウィジェット全体にまたがる青い線を示すインジケーターを置き換えるにはどうすればよいですか?

指定するには:どのタブが選択されているかを示したいのはこれだけです:

  • タブが選択されている場合、tab_button_active.9.pngが背景として表示されます。
  • タブが選択されていない場合、tab_button_inactive.9.pngが背景として表示されます。

編集:tabStripEnabledをfalseに設定しても効果はありません。APIレベル7とActionBarがAPIレベル11で実装されているため、スタイルを追加して「@ android:style/Widget.Holo.ActionBar」を親として使用することもできません。

4

17 に答える 17

41

私はさらに別のハックを持っています。

    TabLayout tabLayout = (TabLayout) fragmentView.findViewById(R.id.tabs);
    tabLayout.setSelectedTabIndicatorHeight(0);

基本的にエレオジャスミルと同じ考え方です。

于 2015-11-16T16:04:47.900 に答える
39

この行app:tabIndicatorHeight="0dp"はxmlで私の問題を解決します

 <android.support.design.widget.TabLayout
        android:id="@+id/view_bottom_tabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabIndicatorHeight="0dp"             //this line
        app:tabGravity="fill"
        app:tabMode="fixed" />
于 2016-01-28T14:06:34.413 に答える
17

うまくいかなかった場合android:tabStripEnabled="false"は、呼び出しもsetStripEnabled(boolean stripEnabled)効果がないと思います。これがすべて当てはまる場合、問題はおそらくTabWidgetにありません。

タブインジケーターを確認することをお勧めします。これらの変更を試してください。このコードは、タブを持つフラグメントから取得されます。

タブインジケータービューを作成するコードは次のとおりです。

    View indicator = LayoutInflater.from(getActivity()).inflate(R.layout.tab,
(ViewGroup) mRoot.findViewById(android.R.id.tabs), false);

        TabSpec tabSpec = mTabHost.newTabSpec(tag);
        tabSpec.setIndicator(indicator);
        tabSpec.setContent(tabContentId);

タブインジケータビューは、おそらくこれに似たものになります。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center"
    android:layout_weight="1"
    android:background="@drawable/tabselector"
    android:padding="5dp" >

    <ImageView
        android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/tab1icon"/>

</LinearLayout>

ここで重要なのandroid:background="@drawable/tabselector"はLinearLayoutです。私のはこんな感じ。

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Non focused states -->
    <item
        android:state_focused="false"
        android:state_selected="false"
        android:state_pressed="false"
        android:drawable="@drawable/tab_unselected_light" />
    <item
        android:state_focused="false"
        android:state_selected="true"
        android:state_pressed="false"
        android:drawable="@drawable/tab_selected_light" />
    <!-- Focused states -->
    <item
        android:state_focused="true"
        android:state_selected="true"
        android:state_pressed="false"
        android:drawable="@drawable/tab_focused_light" />
    <!-- Pressed state -->
    <item
        android:state_pressed="true"
        android:drawable="@drawable/tab_pressed_light" />
</selector>

このtabselector.xmlは、とを交換する場所@drawable/tab_pressed_lightです。@drawable/tab_button_active@drawable/tab_unselected_light@drawable/tab_button_inactive

tabselector.xmlに入るすべてのドローアブルの下部に青い帯がないことを確認してください。あなたの画像を見ると、そのストリップに沿って小さな5pxのギャップがあります。これが、ストリップがTabWidgetからのものではないという考えを私に与えたものです。お役に立てれば。

于 2013-03-07T00:52:00.303 に答える
6

インジケーターの色を透明に変更するだけでよいという1行の答えがあります

color.xml

 <color name="transparent2">#00000000</color>

この行をタブウィジェットに追加します

tabLayout.setSelectedTabIndicatorColor(getResources().getColor(R.color.transparent2));

また

app:tabIndicatorColor="@color/transparent2"
于 2015-11-12T02:44:49.010 に答える
3

使用する

    tabLayout.setSelectedTabIndicator(null);

これにより、選択されたインジケーター ドローアブルが null に設定されます。

于 2019-10-04T06:14:50.877 に答える
2

の属性 android:tabStripEnabled="false"を設定しますTabWidget

于 2013-02-03T12:13:08.197 に答える
-1

ActionBarSherlock を使用していると思います。TabWdiget を使用する際の問題は、ABS の一部ではないため、Android バージョンごとに「ネイティブ」に見えることです。私にとって、ABS を使用したタブ ナビゲーションの最善の方法は、ViewPager と ViewPagerIndicator を使用してインジケーターのスタイルを設定することです。欠点は、タブがフラグメントでなければならないことです。タブをアクティビティにする必要がある場合は、HoloEveryhwhere の担当者が TabWidget を追加できるかどうかを確認する必要があります。

于 2013-03-01T09:06:22.057 に答える
-2
tabHost.getTabWidget().setStripEnabled(false);
tabHost.getTabWidget().getChildAt(1).setBackgroundColor(getResources().getColor(R.color.tabcolor));
tabHost.getTabWidget().getChildAt(2).setBackgroundColor(getResources().getColor(R.color.tabcolor));

詳細はこちら

于 2016-09-22T08:00:09.550 に答える