Android开发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" />  

上面的宽高,根据你需要改动,仅做其他属性示例

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) {

        }

    })

以上就是所有代码了,希望能帮到你

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容