BottonNavigation新增加的第4个按钮项,不影响点击事件

xiaoid 2019-11-22 08:54:10
androidstudio 3.5.2
新建的底部导航栏项目,java语法 , api 23(6.0),被强制勾选了androidx选项。
在ui文件夹里新增加了一个test的Fragment和ViewModel
资源里menu、navigation里都添加了关于test的项。
运行后,默认创建的3个按钮点击有事件响应,第4个点击没有事件响应。
请问是怎么回事?



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BottomNavigationView navView = findViewById(R.id.nav_view);
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
//下面几句不理解是啥子意思,把test也添加进去。
AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications, R.id.navigation_test)
.build();
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
NavigationUI.setupWithNavController(navView, navController);




换成下面的方式,也只有默认的3个按钮有消息,添加的test点击后没有消息。

//绑定点击事件;
navView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.navigation_home:
System.out.println("xxxxxxxxxxxxxxx navigation_homen");
return true;
case R.id.navigation_dashboard:
System.out.println("xxxxxxxxxxxxxxx navigation_dashboard");
return true;
case R.id.navigation_notifications:
System.out.println("xxxxxxxxxxxxxxx navigation_notifications");
return true;
case R.id.navigation_test:
System.out.println("xxxxxxxxxxxxxxx navigation_test");
return true;
}
return false;
}
});




PS:删除重建试了几次,都是一样的效果,点击时有点击的图形效果,但是没有相关的点击事件。

...全文
137 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

80,337

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧