[英]customize the height of tab indicator in view pager?
I am looking to style the tab indicator like pininterest where the indicator does not look like the normal "android" style .我正在寻找像 pininterest 这样的标签指示器的样式,其中指示器看起来不像正常的“android”样式。 Is there some attribute where i can set the indicator height ?Please look into the following image .
是否有一些属性可以设置指标高度?请查看下图。
just set layout_height attribute in your layout file:只需在布局文件中设置 layout_height 属性:
com.viewpagerindicator.TitlePageIndicator
android:layout_height="@dimen/indicator_height"
It might be not a proper solution, and question is really old, but as I haven't found any proper solutions, this is how I did it:这可能不是一个合适的解决方案,问题真的很老,但由于我没有找到任何合适的解决方案,我就是这样做的:
I created a layerList file called indicator:我创建了一个名为指标的 layerList 文件:
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#FF0000" />
</shape>
</item>
<item android:bottom="3dp">
<shape android:shape="rectangle">
<solid android:color="#efefef" />
</shape>
</item>
</layer-list>
And just set it as my tab indicator background:并将其设置为我的选项卡指示器背景:
<style name="CustomTabPageIndicator" parent="@android:style/Widget.Holo.ActionBar.TabView">
<item name="android:background">@drawable/indicator</item>
</style>
I've also applied this theme to my actionBar:我也将此主题应用于我的 actionBar:
<style name="MyActionBarTheme" parent="android:style/Widget.Holo.ActionBar">
<item name="android:actionBarTabStyle">@style/CustomTabPageIndicator</item>
</item> </style>
It works because in indicator.xml first shape is lower shape, which is actual indicator, and to I set its height by providing bottom padding for another shape which color is identical to actionbar color.它起作用是因为在indicator.xml 中第一个形状是较低的形状,它是实际的指示器,并且我通过为另一个颜色与操作栏颜色相同的形状提供底部填充来设置其高度。
Using the material design TabLayout, You can set the height with app:tabIndicatorHeight
使用 Material Design TabLayout,你可以通过
app:tabIndicatorHeight
设置高度
<com.google.android.material.tabs.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorHeight="4dp" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.