一、修改點選的動畫
函式:setUnboundedRipple
這是預設的點選的動畫

mGlueTabLayout.setUnboundedRipple(true);
複製程式碼
這是之後的效果:

二、設定下劃線指示器的寬度不要填充完(動態的根據TabView的寬度來設定自身的寬度)
函式:setTabIndicatorFullWidth
這是預設的效果

mGlueTabLayout.setTabIndicatorFullWidth(false);
複製程式碼
這是之後的效果:

三、設定下劃線指示器的樣式
函式:setSelectedTabIndicator
這是預設的效果

GradientDrawable gradientDrawable = new GradientDrawable();
gradientDrawable.setCornerRadius(dp2px(2));
mGlueTabLayout.setSelectedTabIndicator(gradientDrawable);
複製程式碼
我改變了其的直角,變為了圓角,看效果吧:

res/drawable
資料夾下寫個xml檔案傳入setSelectedTabIndicator(@DrawableRes int tabSelectedIndicatorResourceId)
,效果是一樣的。
這個您也許也需要

所以,我寫了GlueTabLayout
簡單擴充套件了TabLayout
,新增了這個動畫,GlueTabLayout
本質就是TabLayout
,一點未變,您怎麼用TabLayout
,就可以怎麼使用GlueTabLayout
,是不是很友好,哈哈。
我還新增了一個TabLayout
沒有提供的方法,我新增了精確設定下劃線指示器寬度的方法。
我把它開源了,用以方便有需要的人,更詳細的描述移步 GitHub 。
以上 :)