首页滑动到最底部,更改item图标;以及点击item进行页面刷新
public void resetToDefaultIcon(boolean top) {
MenuItem home = navigation.getMenu().findItem(R.id.menu_home);
if (top){
home.setIcon(R.drawable.ic_main_home);
home.setTitle("首页");
}else {
home.setIcon(R.drawable.ic_alipay);
home.setTitle("刷新");
}
home.setOnMenuItemClickListener(item -> {
if (homeFragment != null && homeFragment.isVisible()) {
if (homeFragment instanceof HomeFragment) {
((HomeFragment) homeFragment).getRecyclerView().scrollToPosition(0);
((HomeFragment) homeFragment).initData();
}
}
return false;
});
}
升级到28之后官方有更好的方法解决位移的问题,我们可以直接在 xml 中设置属性
app:labelVisibilityMode="[labeled, unlabeled, selected, auto]"
或者代码中
navigation.setLabelVisibilityMode(LabelVisibilityMode.LABEL_VISIBILITY_LABELED);
- labeled : 保持所有文字便签显示
- unlabeled :只显示图标
- selected :在选中的时候显示文字标签,有动画效果
- auto : 在 1-3 个按钮时使用 labeled ,大于 3 个按钮使用 selected