enter image description here我正在开发一个Android应用程序,我想实现一个类似于图像的菜单,有没有人有任何如何做的例子?
答案 0 :(得分:1)
您肯定应该为每个底部导航Fragment
使用Item / Tab
。与FragmentHome
,FragmentSearch
和FragmentSettings
一样。
要更改Fragment
,请将NavigationItemSelectedListener
添加到BottomNavigationView
,然后根据Fragment
选择更改MenuItem
:
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
的教程这是一个有用的链接:
希望这有助于理解这种情况。
答案 1 :(得分:0)
您可以在此处找到答案:Which view should be used for new Material Design Bottom Navigation?
这是底部菜单的github项目:https://github.com/roughike/BottomBar
答案 2 :(得分:0)