【发布时间】:2017-08-25 20:08:11
【问题描述】:
enter image description here我正在android中开发一个应用程序,我想实现一个类似于图像的菜单,有人有任何示例吗?
【问题讨论】:
enter image description here我正在android中开发一个应用程序,我想实现一个类似于图像的菜单,有人有任何示例吗?
【问题讨论】:
您绝对应该为每个底部导航Item / Tab 使用Fragment。比如FragmentHome、FragmentSearch和FragmentSettings。
要更改Fragment,请将NavigationItemSelectedListener 添加到您的BottomNavigationView 并根据MenuItem 选择更改Fragment:
BottomNavigationView bottomNavigationView = (BottomNavigationView)
findViewById(R.id.bottom_navigation_view);
bottomNavigationView.setOnNavigationItemSelectedListener
(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
Fragment selectedFragment = null;
switch (item.getItemId()) {
case R.id.action_item1:
selectedFragment = FragmentHome.newInstance();
break;
case R.id.action_item2:
selectedFragment = FragmentSearch.newInstance();
break;
case R.id.action_item3:
selectedFragment = FragmentSettings.newInstance();
break;
}
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.frame_layout, selectedFragment);
transaction.commit();
return true;
}
});
这里有一个关于:BottomNavigationView with multiple Fragments的教程
这是一个有用的链接:
希望这将有助于理解该场景。
【讨论】:
您可以在这里找到答案:Which view should be used for new Material Design Bottom Navigation?
这是底部菜单的 github 项目:https://github.com/roughike/BottomBar
【讨论】: