如何在 Android ViewPager 中更改当前选项卡荧光笔颜色?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12408080/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change the current tab highlighter color in Android ViewPager?
提问by intrepidkarthi
Here is my layout inside ViewPager
. I would like to change the color of the current tab highlighter which is below the text. Actually it is showing in black color. But I don't know whether it is a color by default or not. And also I have one more doubt. If I use PagerTitleStrip
this tab highlighter doesn't appear. Is there a way to bring that with titlestrip?
这是我里面的布局ViewPager
。我想更改文本下方的当前选项卡荧光笔的颜色。实际上它显示为黑色。但我不知道它是否是默认颜色。而且我还有一个疑问。如果我使用PagerTitleStrip
此选项卡荧光笔不会出现。有没有办法用标题条带来它?
Here is my layout:
这是我的布局:
<android.support.v4.view.PagerTabStrip android:id="@+id/pager_title_strip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="@color/pager_titlestrip_bg"
android:textColor="@color/pager_titlestrip_text"
android:paddingTop="5dp"
android:paddingBottom="4dp" >
</android.support.v4.view.PagerTabStrip>
回答by intrepidkarthi
This just works.
这只是有效。
PagerTabStrip pagerTabStrip = (PagerTabStrip) findViewById(R.id.pager_title_strip);
pagerTabStrip.setDrawFullUnderline(true);
pagerTabStrip.setTabIndicatorColor(Color.RED);
Thanks!
谢谢!
回答by yubaraj poudel
It can be done in both programmatically with jAVA or with XML
它可以使用 jAVA 或 XML 以编程方式完成
By XML
通过 XML
<android.support.design.widget.TabLayout
android:id="@+id/tabanim_tabs"
android:layout_width="match_parent"
app:tabIndicatorHeight="4dp"
app:tabIndicatorColor="@android:color/white"
android:layout_height="wrap_content" />
Or more simply you can solve this Code aswell
或者更简单地说,您也可以解决此代码
tabLayout.setSelectedTabIndicatorColor(Color.parseColor("#FFFFFF"));
Similarly to change the Height
同样改变高度
tabLayout.setSelectedTabIndicatorHeight((int) (2 * getResources().getDisplayMetrics().density));
回答by Dhaval Shingala
This works in my project.
这适用于我的项目。
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFF"
app:tabGravity="fill"
app:tabIndicatorColor="@color/text3"
app:tabMode="scrollable"
app:tabSelectedTextColor="@color/text3"
app:tabTextColor="#000" />