Android開發(fā)CommonTabLayout的用法

前言

因為com.flyco.tablayout.CommonTabLayout不跟ViewPager掛鉤,所以用的比較少。在這記錄下它的用法

示例代碼:

xml:

            <com.flyco.tablayout.CommonTabLayout
                android:id="@+id/common_tabLayout"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:background="@color/white"
                app:layout_constraintLeft_toRightOf="@+id/back_button"
                app:layout_constraintRight_toLeftOf="@id/bar_right_image"
                app:tl_indicator_color="@color/m_red_one"
                app:tl_indicator_corner_radius="1.5dp"
                app:tl_indicator_height="3dp"
                app:tl_indicator_width="44dp"
                app:tl_tab_space_equal="true"
                app:tl_textBold="BOTH"
                app:tl_textSelectColor="@color/m_red_one"
                app:tl_textUnselectColor="@color/c_33"
                app:tl_textsize="@dimen/m_size_16"
                app:tl_underline_color="@color/c_f2f2f7"
                app:tl_underline_height="1px" />  

上面的寬高,根據(jù)你需要改動,僅做其他屬性示例

kotlin代碼:

val tabEntities = java.util.ArrayList<CustomTabEntity>()
    tabEntities.add(object :CustomTabEntity{
        override fun getTabUnselectedIcon(): Int {
            return 0
        }

        override fun getTabSelectedIcon(): Int {
            return 0
        }

        override fun getTabTitle(): String {
            return "xxx標題1"
        }

    })
    tabEntities.add(object :CustomTabEntity{
        override fun getTabUnselectedIcon(): Int {
            return 0
        }

        override fun getTabSelectedIcon(): Int {
            return 0
        }

        override fun getTabTitle(): String {
            return "xxx標題2"
        }

    })
    common_tabLayout.setTabData(tabEntities)

    common_tabLayout.setOnTabSelectListener(object :OnTabSelectListener{
        override fun onTabSelect(position: Int) {
            when(position){
                0 -> {
                    
                }
                1 -> {
                    
                }
            }
        }

        override fun onTabReselect(position: Int) {

        }

    })

以上就是所有代碼了,希望能幫到你

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容