我有TabLayout 2个问题
1)我可以删除TabLayout亮点或更改标签布局的高亮颜色?
2)我可以添加标签连锁反应。 每个选项卡包含的TextView我尝试添加自定义背景是这样的
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:colorControlHighlight">
<item android:drawable="@drawable/btn_white_bg" />
</ripple>
但它不工作。
这对我的作品的另一个解决方案
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:minHeight="?attr/actionBarSize"
android:layout_width="match_parent"
app:tabMode="fixed"
app:tabGravity="fill"
android:clipToPadding="false"
android:elevation="0dp"
style="@style/MyCustomTabLayout"
android:background="@color/colorPrimary"
app:tabBackground="?attr/selectableItemBackground"
app:tabIndicatorColor="@color/app_yellow"
app:tabIndicatorHeight="4dip"
android:layout_height="wrap_content"/>
我只是增加了以下几行
机器人:背景= “@颜色/ colorPrimary”
应用:tabBackground = “?ATTR / selectableItemBackground”
您可以自定义TabLayout这样的:做一个XML文件中值MyCustomTabLayout.xml
,然后把这些
<resources>
<style name="MyCustomTabLayout" parent="Widget.Design.TabLayout">
<item name="tabMaxWidth">@dimen/tab_max_width</item>
<item name="tabIndicatorColor">@color/black</item>
<!-- <item name="tabIndicatorColor">?attr/colorAccent</item> -->
<item name="tabIndicatorHeight">5dp</item>
<item name="tabPaddingStart">12dp</item>
<item name="tabPaddingEnd">12dp</item>
<item name="tabBackground">?attr/selectableItemBackground</item>
<item name="tabTextAppearance">@style/MyCustomTabTextAppearance</item>
<item name="tabSelectedTextColor">?android:textColorPrimary</item>
</style>
<style name="MyCustomTabTextAppearance" parent="TextAppearance.Design.Tab">
<item name="android:textSize">16sp</item>
<item name="android:textColor">?android:textColorSecondary</item>
<item name="textAllCaps">true</item>
</style>
和UR布局内补充一点:
<android.support.design.widget.TabLayout
android:id="@+id/mainSlidingTab"
style="@style/MyCustomTabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/tool_bar"
android:background="@color/ColorPrimary" />
<!-- app:tabMode="scrollable" when many tabs -->
要删除的亮点,下面的行添加到您的XML:
app:tabRippleColor="@android:color/transparent"