自定義TabLayout,可以更改下方指標樣式爲圖片

自定義可以設置圖片的TabLayout,可以更改下方指標樣式爲圖片,指定字體默認大小和選中字體大小、顏色等屬性。

 

# ImgTabLayout

示例圖片:

 

 

在XML佈局文件中添加 ImgTabLayout

<com.zgq.imgtablibrary.ImgTabLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

xml佈局文件指定樣式


<com.zgq.imgtablibrary.ImgTabLayout
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="56dp"
        app:viewHeight="56dp"
        app:viewWidth="84dp"
        app:mTextColorDef="@color/c666666"
        app:mTextColorSelect="@color/cfc9464"
        app:textSize="16sp"
        app:textSizeSel="22sp"
        app:indicatorWidth="20dp"
        app:indicatorHeight="30dp"
        app:indicatorBgResId="@mipmap/icon"
        app:mTextBgDefResId="@mipmap/ic_launcher"
        app:mTextBgSelectResId="@color/c2aa9c9"/>
    
    <!--是屬性說明-->    
    <!--viewHeight, viewWidth : tablayout中TextView的寬高(注意:由於點擊事件是在textView上
    ,所以最好把textView的高度設置成tab的高度)-->
        <!--mTextColorDef,mTextColorSelect :文字的默認和選中時的顏色-->
    <!--textSize,textSizeSel :文字的默認和選中時的大小,textSizeSel不設置則統一默認大小,如果
     設置了不同大小,viewWidth一定要指定寬度,不然下方指標會錯位-->
    <!--indicatorWidth,indicatorHeight :文字下方指標的寬高-->
    <!--indicatorBgResId :文字下方指標的顯示資源,可以是圖片也可以是顏色-->
    <!--mTextBgDefResId , mTextBgSelectResId:文字背景設置, 默認背景和選中背景-->
```

上面的所有屬性,都有開放有 set 方法,方便在java類中使用

最後
希望這個view對你有所幫助
具體的可以下載demo自個兒看,其實代碼不多。使用時可以添加上方依賴,也可以拷貝源碼。
如果有bug,或者能改進優化,請留言聯繫我

GitHUb地址:https://github.com/zuoguiqing/ImgTabLayout

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章