[英]Add click event on menu item
I am using bottom navigation bar, so I used three menu item in bottom navigation bar, my question is that I want to add some click eventon that button so when a user click on home button, it will come to the main activity from any activity and when user click on search bar, it will get a floating search bar in the bottom. 我正在使用底部导航栏,所以我在底部导航栏中使用了三个菜单项,我的问题是我想在该按钮上添加一些单击事件,因此当用户单击主页按钮时,它将从任何活动进入主活动当用户点击搜索栏时,它的底部会出现一个浮动的搜索栏。
Put this code in onCreate() of your activity 将此代码放在您活动的onCreate()中
BottomNavigationView bottomNavigationView = (BottomNavigationView)findViewById(R.id.bottom_navigation);
bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.home:
//Add your action onClick
break;
case R.id.search:
break;
case R.id.favorite:
break;
}
return false;
}
});
Here is the tutorial teach you add bottom navigation bar step by step. 这是本教程,教您逐步添加底部导航栏。
see : blog_iamsuleiman 看到: blog_iamsuleiman
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.