【问题标题】:How to remove the selected tab indicator from the FragmentTabhost?如何从 FragmentTabhost 中删除选定的选项卡指示器?
【发布时间】:2016-09-27 06:20:38
【问题描述】:

我尝试了几个链接来删除FragmentTabHost 中的选定选项卡,但对我不起作用。
First link
Second link

我也在我的 Xml 中尝试过,但它不起作用

android:tabStripEnabled="false"

这是我对 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>

在我的设备中选择的标签看起来像(请检查图像)

Moto E 设备


HTC 设备

【问题讨论】:

    标签: android android-tabhost fragment-tab-host


    【解决方案1】:

    抱歉回复晚了 我也遇到了这个问题,我尝试了很多方法,终于成功了。

    试试下面的代码。

     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("你的标签位置").setBackground(null);

    只需获取孩子并将其背景设置为 null 即可完成

    【讨论】:

    • ..感谢您对此的回复..+1 您的努力...现在我对它没有任何要求...将来会测试(所以我现在不接受它。 ...) ,我什么时候会做这种类型的任务..谢谢
    • 感谢您的 +1,这是我发布答案并始终欢迎的责任
    • 此解决方案还将删除 onclick 动画。
    猜你喜欢
    • 1970-01-01
    • 2021-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多