【问题标题】:How to create a Menu Bottom of this type in Android?如何在 Android 中创建这种类型的菜单底部?
【发布时间】:2017-08-25 20:08:11
【问题描述】:

enter image description here我正在android中开发一个应用程序,我想实现一个类似于图像的菜单,有人有任何示例吗?

【问题讨论】:

    标签: android menu


    【解决方案1】:

    您绝对应该为每个底部导航Item / Tab 使用Fragment。比如FragmentHomeFragmentSearchFragmentSettings

    要更改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的教程

    这是一个有用的链接:

    1. Android Toolbar Adding Menu Items for different fragments

    希望这将有助于理解该场景。

    【讨论】:

      【解决方案2】:

      您可以在这里找到答案:Which view should be used for new Material Design Bottom Navigation?

      这是底部菜单的 github 项目:https://github.com/roughike/BottomBar

      【讨论】:

        【解决方案3】:
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多