java 代码
private String[] mTitles = {“首页”, “消息”, “联系人”, “更多”};
private int[] mIconUnselectIds = {
R.mipmap._tab\_home\_unselect_, R.mipmap._tab\_speech\_unselect_,
R.mipmap._tab\_contact\_unselect_, R.mipmap._tab\_more\_unselect_};
private int[] mIconSelectIds = {
R.mipmap._tab\_home\_select_, R.mipmap._tab\_speech\_select_,
R.mipmap._tab\_contact\_select_, R.mipmap._tab\_more\_select_};
private ArrayList mTabEntities = new ArrayList<>();
private CommonTabLayout mTabLayout_1;
for (int i = 0; i < mTitles.length; i++) {
mTabEntities.add(new TabEntity(mTitles\[i\], mIconSelectIds\[i\], mIconUnselectIds\[i\]));
}
mTabLayout_1.setTabData(mTabEntities);
mTabLayout_1.setOnTabSelectListener(new OnTabSelectListener() {
@Override
public void onTabSelect(int position) {
Log.i("lgqq","body=====接受到推送下来的消息=1111111111111"+position);//底部item事件
}
@Override
public void onTabReselect(int position) {
}
});
TabEntity类
public class TabEntity implements CustomTabEntity {
public String title;
public int selectedIcon;
public int unSelectedIcon;
public TabEntity(String title, int selectedIcon, int unSelectedIcon) {
this.title \= title;
this.selectedIcon \= selectedIcon;
this.unSelectedIcon \= unSelectedIcon;
}
@Override
public String getTabTitle() {
return title;
}
@Override
public int getTabSelectedIcon() {
return selectedIcon;
}
@Override
public int getTabUnselectedIcon() {
return unSelectedIcon;
}
}
显示未读消息或显示未读红点
//显示未读红点
mTabLayout_1.showDot(2);
MsgView rtv_1_2 = mTabLayout_1.getMsgView(2);
if (rtv_1_2 != null) {
if (rtv\_1\_2 instanceof SkinMsgView) {
((SkinMsgView) rtv\_1\_2).setBackgroundColorResource(R.color._msg\_background\_color_);
}
}
mTabLayout_3.showDot(1);
MsgView rtv_3_1 = mTabLayout_3.getMsgView(1);
if (rtv_3_1 != null) {
if (rtv\_3\_1 instanceof SkinMsgView) {
((SkinMsgView) rtv\_3\_1).setBackgroundColorResource(R.color._msg\_background\_color_);
}
}
mTabLayout_4.showDot(1);
MsgView rtv_4_1 = mTabLayout_4.getMsgView(1);
if (rtv_4_1 != null) {
if (rtv\_4\_1 instanceof SkinMsgView) {
((SkinMsgView) rtv\_4\_1).setBackgroundColorResource(R.color._msg\_background\_color_);
}
}
//两位数
mTabLayout_2.showMsg(0, 55);
MsgView rtv_2_0 = mTabLayout_2.getMsgView(0);
if (rtv_2_0 != null) {
if (rtv\_2\_0 instanceof SkinMsgView) {
((SkinMsgView) rtv\_2\_0).setBackgroundColorResource(R.color._msg\_background\_color_);
}
}
mTabLayout_2.setMsgMargin(0, -5, 5);
//三位数
mTabLayout_2.showMsg(1, 66);
MsgView rtv_2_1 = mTabLayout_2.getMsgView(1);
if (rtv_2_1 != null) {
if (rtv\_2\_1 instanceof SkinMsgView) {
((SkinMsgView) rtv\_2\_1).setBackgroundColorResource(R.color._msg\_background\_color_);
}
}
mTabLayout_2.setMsgMargin(1, -5, 5);
//设置未读消息红点
mTabLayout_2.showDot(2);
MsgView rtv_2_2 = mTabLayout_2.getMsgView(2);
if (rtv_2_2 != null) {
UnreadMsgUtils.setSize(rtv\_2\_2, dp2px(7.5f));
((SkinMsgView) rtv\_2\_2).setBackgroundColorResource(R.color._t2\_2\_background_);
}
//设置未读消息背景
mTabLayout_2.showMsg(3, 5);
mTabLayout_2.setMsgMargin(3, 0, 5);
MsgView rtv_2_3 = mTabLayout_2.getMsgView(3);
if (rtv_2_3 != null) {