【问题标题】:Remove bottom line from tab bar从标签栏中删除底线
【发布时间】:2013-10-21 22:27:31
【问题描述】:

我想删除出现在标签栏底部的默认行。我尝试了以下操作:

android:tabStripEnabled="false"  
tabHost.getTabWidget.setStripEnabled(false);  

还尝试按照question 的建议包装在 LinearLayout 中

如何删除该行?

【问题讨论】:

    标签: android tabbar


    【解决方案1】:

    在 TabLayout 中使用该属性

    app:tabIndicatorColor="@android:color/transparent"
    

    完整示例:

    <com.google.android.material.tabs.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="@dimen/_27sdp"
        android:layout_marginLeft="@dimen/_5sdp"
        android:layout_marginTop="@dimen/_10sdp"
        android:layout_marginRight="@dimen/_5sdp"
        android:background="@drawable/blue_button"
        app:tabIndicatorColor="@android:color/transparent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/challengeType"
        app:tabGravity="fill"
       >
    

    【讨论】:

      【解决方案2】:

      使用此代码并从 tabhost 底部删除行

      android:tabStripEnabled="true"  
      tabHost.getTabWidget.setStripEnabled(true);  
      

      【讨论】:

        【解决方案3】:

        我使用自定义视图从标签栏中删除行。

        标签视图的自定义布局:

            <ImageView
                android:id="@+id/tab_icon"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:layout_gravity="center"
                android:contentDescription="@string/tab_desc"
                android:gravity="center" />
        
        </LinearLayout>
        

        设置标签视图:

        private void setUpTabs() {
            TabSpec spec0 = tabHost.newTabSpec("Tab");
            spec0.setContent(R.id.tab_list);
            spec0.setIndicator(tabView(R.drawable.image));
            tabHost.addTab(spec0);
        }
        
        
        // Return view for tab
        private View tabView(int drawableId) {
            View view = LayoutInflater.from(this).inflate(R.layout.tab_image,
                                        tabHost.getTabWidget(), false);
            ImageView imageView = (ImageView) view.findViewById(R.id.tab_icon);
            imageView.setImageResource(drawableId);
            return view;
        }
        

        【讨论】:

          【解决方案4】:

          我使用

          删除了它
           // Create Child Tab1
              mTabHost.addTab(mTabHost.newTabSpec("child1").setIndicator("your text",getResources().getDrawable(R.drawable.your_image)),
                      yourclass.class, null);
          
           mTabHost.getTabWidget().getChildAt(0).setBackgroundColor(getResources().getColor(R.color.your background color));
              mTabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.your_image);
          

          我设置了背景颜色,然后使用上面的代码设置标签上的图片蓝线自动消失了,希望对你有所帮助。

          【讨论】:

          • 我已经有了 tabWidget 的背景图片。设置背景颜色会覆盖图像。
          • 你试过设置这个吗?当您设置背景颜色时,它会隐藏那条蓝线。
          • 是的,我做到了。但这也隐藏了图像。
          • 试过了。底部还有那条线。
          猜你喜欢
          • 2020-04-18
          • 1970-01-01
          • 2021-03-15
          • 2020-01-24
          • 1970-01-01
          • 2020-12-04
          • 1970-01-01
          • 1970-01-01
          • 2016-02-22
          相关资源
          最近更新 更多