drawable文件夹下
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_history_more" android:state_pressed="true"></item>
<item android:drawable="@drawable/ic_history_more" android:state_focused="true"></item>
<item android:drawable="@drawable/ic_history_more" android:state_selected="true"></item>
<item android:drawable="@drawable/ic_history_more"></item>
</selector>
drawable-v21文件夹下
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/ripple_color">
<item>
<selector>
<item
android:drawable="@drawable/ic_history_more"
android:state_pressed="true">
</item>
<item
android:drawable="@drawable/ic_history_more"
android:state_pressed="false">
</item>
</selector>
</item>
</ripple>
RelativeLayout水波纹
android:clickable="true"
android:background="@drawable/selector_bg_ripple"
drawable文件夹下
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/ripple_color" android:state_focused="true" />
<item android:drawable="@color/ripple_color" android:state_pressed="true" />
<item android:drawable="@color/ripple_color" android:state_selected="true" />
<item android:drawable="@android:color/transparent" />
</selector>
drawable-v21文件夹下
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/ripple_color">
<item>
<color android:color="@color/colorTransparent" />
</item>
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="?android:colorAccent"></solid>
</shape>
</item>
</ripple>
TabLayout 自定义
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayoutMainActivity"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="@color/color_theme"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolBarMainActivity"
app:tabIndicatorColor="@color/color_white"
app:tabIndicatorHeight="2.3dp"
app:tabMode="fixed"
app:tabPaddingStart="-1dp"
app:tabPaddingEnd="-1dp"
app:tabTextAppearance="@style/CustomTabLayoutTextAppearance"
app:tabTextColor="@color/color_white" />
tabFirstItem = tabLayoutMainActivity.newTab().setCustomView(R.layout.layout_tab_download)
layout_tab_download如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/selector_bg_ripple"
android:padding="@dimen/dp_0"
android:gravity="center">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tvTabDownLoad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="@string/str_download"
android:textColor="@color/color_white"
android:textSize="@dimen/sp_16" />
</RelativeLayout>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/ripple_color">
<item>
<color android:color="@color/colorTransparent" />
</item>
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="?android:colorAccent"></solid>
</shape>
</item>
</ripple>
注意事项:
app:tabPaddingStart="-1dp" 表示tab的paddingleft 是多少
app:tabPaddingEnd="-1dp" 表示tab的paddingright 是多少
如果不添加这两句,则自定义的布局未完全填充tabLayout