4.1QMUI----QMUITabSegment的用法

基本方法:

mTabSegment.reset();//重置
mTabSegment.notifyDataChanged();//刷新

1.只有文字

mTabSegment.setHasIndicator(false);
mTabSegment.addTab(new QMUITabSegment.Tab("1"));
mTabSegment.addTab(new QMUITabSegment.Tab("2"));
2.文字+底部indicator

mTabSegment.setHasIndicator(true);  //是否需要显示indicator
mTabSegment.setIndicatorPosition(false);//true 时表示 indicator 位置在 Tab 的上方, false 时表示在下方
mTabSegment.setIndicatorWidthAdjustContent(true);//设置 indicator的宽度是否随内容宽度变化
mTabSegment.addTab(new QMUITabSegment.Tab("1"));
mTabSegment.addTab(new QMUITabSegment.Tab("2"));
3.文字+顶部indicator

mTabSegment.setHasIndicator(true);  //是否需要显示indicator
mTabSegment.setIndicatorPosition(true);//true 时表示 indicator 位置在 Tab 的上方, false 时表示在下方
mTabSegment.setIndicatorWidthAdjustContent(true);//设置 indicator的宽度是否随内容宽度变化
mTabSegment.addTab(new QMUITabSegment.Tab("1"));
mTabSegment.addTab(new QMUITabSegment.Tab("2"));
4. 文字+indicator长度不跟随内容长度

mTabSegment.setHasIndicator(true);  //是否需要显示indicator
mTabSegment.setIndicatorPosition(false);//true 时表示 indicator 位置在 Tab 的上方, false 时表示在下方
mTabSegment.setIndicatorWidthAdjustContent(false);//设置 indicator的宽度是否随内容宽度变化
mTabSegment.addTab(new QMUITabSegment.Tab("1"));
mTabSegment.addTab(new QMUITabSegment.Tab("2"));
5.文字+icon(支持四个方向)+自动着色选中icon

mTabSegment.setHasIndicator(false);
QMUITabSegment.Tab component = new QMUITabSegment.Tab(
        ContextCompat.getDrawable(getContext(), R.mipmap.icon_tabbar_component),
        null,
        "Components", true
);
QMUITabSegment.Tab util = new QMUITabSegment.Tab(
        ContextCompat.getDrawable(getContext(), R.mipmap.icon_tabbar_util),
        null,
        "Helper", true
);
mTabSegment.addTab(component);
mTabSegment.addTab(util);
6.显示小红点

QMUITabSegment.Tab tab = mTabSegment.getTab(0);
tab.setSignCountMargin(0, -QMUIDisplayHelper.dp2px(getContext(), 4));
tab.showSignCountView(getContext(), 1);
隐藏Tab上的未读数或红点

tab.hideSignCountView();
7.更换选中的icon图标

mTabSegment.setHasIndicator(false);
QMUITabSegment.Tab component2 = new QMUITabSegment.Tab(
        ContextCompat.getDrawable(getContext(), R.mipmap.icon_tabbar_component),
        ContextCompat.getDrawable(getContext(), R.mipmap.icon_tabbar_component_selected),
        "Components", false
);
QMUITabSegment.Tab util2 = new QMUITabSegment.Tab(
        ContextCompat.getDrawable(getContext(), R.mipmap.icon_tabbar_util),
        ContextCompat.getDrawable(getContext(), R.mipmap.icon_tabbar_util_selected),
        "Helper", false
);
mTabSegment.addTab(component2);
mTabSegment.addTab(util2);
8.不同item,不同文字(icon)颜色

mTabSegment.setHasIndicator(true);
mTabSegment.setIndicatorWidthAdjustContent(true);
mTabSegment.setIndicatorPosition(false);
QMUITabSegment.Tab component3 = new QMUITabSegment.Tab(
        ContextCompat.getDrawable(getContext(), R.mipmap.icon_tabbar_component),
        null,
        "Components", true
);
component3.setTextColor(QMUIResHelper.getAttrColor(getContext(), R.attr.qmui_config_color_blue),
        QMUIResHelper.getAttrColor(getContext(), R.attr.qmui_config_color_red));
QMUITabSegment.Tab util3 = new QMUITabSegment.Tab(
        ContextCompat.getDrawable(getContext(), R.mipmap.icon_tabbar_util),
        null,
        "Helper", true
);
util3.setTextColor(QMUIResHelper.getAttrColor(getContext(), R.attr.qmui_config_color_gray_1),
        QMUIResHelper.getAttrColor(getContext(), R.attr.qmui_config_color_red));
mTabSegment.addTab(component3);
mTabSegment.addTab(util3);
9.根据index更新tab文案

mTabSegment.updateTabText(0, "动态更新文案");
10.根据index完全替换tab

QMUITabSegment.Tab component4 = new QMUITabSegment.Tab(
        ContextCompat.getDrawable(getContext(), R.mipmap.icon_tabbar_component),
        null,
        "动态更新", true
);
mTabSegment.replaceTab(0, component4);




你可能感兴趣的:(QMUI)