美文网首页
FlycoTabLayout选中和未选中状态下改变字体大小

FlycoTabLayout选中和未选中状态下改变字体大小

作者: jxtx | 来源:发表于2020-09-24 16:24 被阅读0次

GitHub:FlycoTabLayout
实现方式有很多,很多人修改源码,添加自定义属性来实现,GitHub已经有人回答了
这里采取监听方式来实现
记录一下,方便以后查找

 <com.flyco.tablayout.SlidingTabLayout
        android:id="@+id/stl"
        android:layout_width="match_parent"
        android:layout_height="43dp"
        android:layout_marginLeft="36dp"
        app:tl_indicator_color="@color/color_329902"
        app:tl_textSelectColor="@color/color_333333"
        app:tl_textUnselectColor="@color/color_666666"
        app:tl_textsize="8sp"
        app:tl_indicator_margin_bottom="9dp"
        app:tl_indicator_width="40dp"
        app:tl_underline_gravity="BOTTOM"
        app:tl_underline_height="3dp" />



 binding.stl.setCurrentTab(currenTab);
        binding.stl.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                updateTabView(position);

            }

            @Override
            public void onTabReselect(int position) {

            }
        });

        updateTabView(currenTab);
        binding.vp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                updateTabView(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });


 //动态修改tab字体选中和未选中的大小
    private void updateTabView(int position) {
        int tabCount = binding.stl.getTabCount();
        for (int i=0;i<tabCount;i++){
            TextView title = binding.stl.getTitleView(i);
            if (i==position){
//                        TextView title = child.findViewById(com.flyco.tablayout.R.id.tv_tab_title);
                title.setTextSize(TypedValue.COMPLEX_UNIT_PX, DisplayUtils.sp2px(CouseStudyActivity.this,9));
            }else {
//                        TextView title = child.findViewById(com.flyco.tablayout.R.id.tv_tab_title);
                title.setTextSize(TypedValue.COMPLEX_UNIT_PX,DisplayUtils.sp2px(CouseStudyActivity.this,8));
            }
        }
    }




相关文章

网友评论

      本文标题:FlycoTabLayout选中和未选中状态下改变字体大小

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