为 TabLayout 移除当前 Tab 下的选择器行 [英] Remove the selector line under current Tab for a TabLayout
问题描述
我正在使用带有 3 个选项卡的 TabLayout.我自定义了标签的视图,因此,我需要删除标签下的以下行(屏幕截图不是来自我的应用):
I am using a TabLayout with 3 tabs. I customized the view of my tabs and therefor, I need to remove the following line under my tabs ( the screenshot doesnt come from my app):
我不使用 TabHost 或 TabWidget,因此,我不能使用 setStripEnabled(false)
.将背景设置为透明也不会改变任何东西.
I am NOT using a TabHost or a TabWidget and therefor, I cannot use setStripEnabled(false)
. Setting the background to transparent doesnt change anything as well.
这是我的 xml:
<android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:padding="4dip"
android:layout_above="@+id/bottomcontent3"
android:gravity="center_horizontal"
android:background="@android:color/white"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.TabLayout
android:id="@+id/comtabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
app:tabPaddingStart="0dp"
app:tabPaddingEnd="0dp"
app:tabMode="fixed"
app:tabGravity="fill"
android:background="@android:color/white" />
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/compager"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v4.view.ViewPager>
</android.support.design.widget.AppBarLayout>
我找到的所有答案都是使用 TabHost
、TabWidget
.就我而言,我使用了一个 TabLayout
和三个 Tab
.在这种情况下如何删除此行?非常感谢.
All the answer I found were using TabHost
, TabWidget
. In my case, I'm using one TabLayout
and three Tab
.
How can I remove this line in this case? Thanks a lot.
EDIT 由于某些原因,无法在我的代码中解析来自 TabLayout 的某些方法.有我使用的java代码:
EDIT Some methods from TabLayout can't be resolved in my code for some reasons. There is the java code I use:
TabLayout tabLayout = (TabLayout) view.findViewById(R.id.comtabs);
tabLayout.setTabMode(TabLayout.MODE_FIXED);
// add tabs
tabLayout.addTab(tabLayout.newTab());
tabLayout.addTab(tabLayout.newTab());
tabLayout.addTab(tabLayout.newTab());
RelativeLayout layout1 = (RelativeLayout) inflater.inflate(R.layout.communitytablayoutleft, container, false);
RelativeLayout layout2 = (RelativeLayout) inflater.inflate(R.layout.communitytablayout, container, false);
RelativeLayout layout3 = (RelativeLayout) inflater.inflate(R.layout.communitytablayoutright, container, false);
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
ViewPager pager = (ViewPager) view.findViewById(R.id.compager);
CommunityPagerFragment adapter = new CommunityPagerFragment(getChildFragmentManager());
pager.setAdapter(adapter);
tabLayout.setupWithViewPager(pager);
tabLayout.setOnTabSelectedListener(this);
((TextView)layout1.findViewById(R.id.tabtext)).setText(tabs[0]);
((TextView)layout2.findViewById(R.id.tabtext)).setText(tabs[1]);
((TextView)layout3.findViewById(R.id.tabtext)).setText(tabs[2]);
tabLayout.getTabAt(0).setCustomView(layout1);
tabLayout.getTabAt(1).setCustomView(layout2);
tabLayout.getTabAt(2).setCustomView(layout3);
//tabLayout.set
return view;
及其导入:
import android.support.design.widget.TabLayout;
推荐答案
正如两个答案所建议的,关键是 tabIndicatorHeight
属性.
As the two answers suggested, the key was the tabIndicatorHeight
attribute.
但是,由于某些原因,API 中的方法无法解决.在这种情况下,您必须直接从 xml 中修复此问题,如下所示:
However the method from the API was, for some reasons, unable to be solved. In this case you have to fix this directly from the xml, this way:
app:tabIndicatorHeight="0dp"
在您的
布局中.
举个例子:
<android.support.design.widget.TabLayout
android:id="@+id/comtabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
app:tabIndicatorHeight="0dp"
app:tabPaddingStart="0dp"
app:tabPaddingEnd="0dp"
app:tabMode="fixed"
app:tabGravity="fill"
android:background="@android:color/white" />
这篇关于为 TabLayout 移除当前 Tab 下的选择器行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!