美文网首页
Android开发CommonTabLayout的用法

Android开发CommonTabLayout的用法

作者: 你的益达233 | 来源:发表于2021-01-25 15:21 被阅读0次

    前言

    因为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) {
    
            }
    
        })
    

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

    相关文章

      网友评论

          本文标题:Android开发CommonTabLayout的用法

          本文链接:https://www.haomeiwen.com/subject/qrfizktx.html