How do I remove the selected tab indicator from the TabWidget?

后端 未结 17 1256
猫巷女王i
猫巷女王i 2020-12-09 02:19

Here\'s what I\'d like to remove :

\"enter

How do I replace the indicator show

相关标签:
17条回答
  • 2020-12-09 03:00

    If android:tabStripEnabled="false" did not work then I also assume calling setStripEnabled(boolean stripEnabled) will have no effect as well. If all of this is true then your problem is probably not in TabWidget.

    I would suggest looking at your tab indicator. Try these modifications. This code is taken from a fragment that has tabs.

    Here is the code that creates the tab indicator view.

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

    Your tab indicator view would probably like similar to this.

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

    Now the important part here is the android:background="@drawable/tabselector" in the LinearLayout. Mine looks like this.

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

    This tabselector.xml is where you will swap @drawable/tab_pressed_light with your @drawable/tab_button_active and @drawable/tab_unselected_light with @drawable/tab_button_inactive

    Be sure to check that all of your drawables that go into your tabselector.xml do not have the blue strips along the bottom. As I look at your image I can see little 5px gaps along that strip this is what gave me the idea that the strip was not from your TabWidget. Hope this helps.

    0 讨论(0)
  • 2020-12-09 03:02

    I assume you are using ActionBarSherlock. The problem with using a TabWdiget is, that it is not part of ABS, so it will look "native" for each Android Version. For me, the best approach for tab navigtion with ABS is to use a ViewPager and ViewPagerIndicator and style the indicator. Downside is, that your tabs must be fragments. If you need your tabs to be activities then you should take a look if the guys at HoloEveryhwhere have managed to add the TabWidget.

    0 讨论(0)
  • 2020-12-09 03:03
    tabHost.getTabWidget().setStripEnabled(false);
    tabHost.getTabWidget().getChildAt(1).setBackgroundColor(getResources().getColor(R.color.tabcolor));
    tabHost.getTabWidget().getChildAt(2).setBackgroundColor(getResources().getColor(R.color.tabcolor));
    

    More info here

    0 讨论(0)
  • 2020-12-09 03:04

    Set attribute android:tabStripEnabled="false" for your TabWidget.

    0 讨论(0)
  • 2020-12-09 03:07

    there is one line answer to that you have only to change the color of the indicator into a transparent

    color.xml

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

    and put this line to your tabwidget

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

    or

    app:tabIndicatorColor="@color/transparent2"
    
    0 讨论(0)
提交回复
热议问题