How to remove the selected tab indicator from the FragmentTabhost?

泪湿孤枕 提交于 2019-12-24 07:51:49

问题


I have tried several links for remove the selected tab in FragmentTabHost but does not work for me .
First link
Second link

I have tried this also in my Xml but it is not working

android:tabStripEnabled="false"

And it is my layout for the fragmenttabhost.

<FrameLayout

    android:id="@+id/realtabcontent"
    android:layout_width="match_parent"
    android:layout_weight="1"
    android:layout_height="0dp"
     />
    <android.support.v4.app.FragmentTabHost
      android:id="@android:id/tabhost"
      android:layout_width="match_parent"
      android:layout_alignParentBottom="true"
      android:background="@drawable/top_bg"
      app:tabIndicatorColor="#000"
      android:tabStripEnabled="false"
      app:tabIndicatorHeight="0dp"
      android:layout_height="60dp"
      >

    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0" />

    <LinearLayout
        android:id="@+id/tab_layout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:showDividers="none"
        android:orientation="horizontal"
        android:weightSum="5" >

        <ImageView
            android:id="@+id/genralTabBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"
            android:padding="15dp"
            android:background="@drawable/button_1_off" />

        <ImageView
            android:id="@+id/treandingTabBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"
            android:padding="12dp"
            android:background="@drawable/button_2_off" />

        <ImageView
            android:id="@+id/profileTabBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"
            android:padding="12dp"
            android:background="@drawable/button_3_off" />

</android.support.v4.app.FragmentTabHost>

And in my devices selected tab look like (Plz check images)

Moto E device


HTC device


回答1:


Sorry For Late Reply I am also getting this issue and I tried many things on it and finally I get success.

Try This Below code.

 fragmentTabHost.addTab(fragmentTabHost.newTabSpec("tab1").setIndicator("", getResources().getDrawable(R.drawable.tab1)),
            HomeFragment.class, null);

    fragmentTabHost.getTabWidget().getChildAt(0).setBackground(null);//set child background as null 
    fragmentTabHost.addTab(fragmentTabHost.newTabSpec("tab2").setIndicator("", getResources().getDrawable(R.drawable.tab2)),
            CartFragment.class, null);
    fragmentTabHost.getTabWidget().getChildAt(1).setBackground(null););//set child background as null 

    fragmentTabHost.addTab(fragmentTabHost.newTabSpec("tab3").setIndicator("", getResources().getDrawable(R.drawable.tab3)),
            MoreStuffFragment.class, null);
    fragmentTabHost.getTabWidget().getChildAt(2).setBackground(null); );//set child background as null 

fragmentTabHost.getTabWidget().getChildAt("Your tab position").setBackground(null);

Simply you have to get child and set it's background as null and you have done



来源:https://stackoverflow.com/questions/39717362/how-to-remove-the-selected-tab-indicator-from-the-fragmenttabhost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!