BottomNavigationView
来实现底部菜单栏。以下是一个简单的实例代码:,,``xml,,
`,,在
res/menu/bottom_nav_menu.xml中定义菜单项:,,
`xml,,,,,,
`,,在Activity中设置监听器:,,
`java,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.navigation_home:, // Handle home action, return true;, case R.id.navigation_dashboard:, // Handle dashboard action, return true;, case R.id.navigation_notifications:, // Handle notifications action, return true;, }, return false;, },});,
``Powered By Z-BlogPHP 1.7.3