【问题标题】:Open alert dialog in Bottom Navigation View while navigation to next fragment在导航到下一个片段时在底部导航视图中打开警报对话框
【发布时间】:2020-06-04 10:29:53
【问题描述】:

我的活动中有一个 BottomNavigationView,我有五个片段,并且我使用了 Navigation Jetpack 组件。

每次我通过单击底部导航视图项移动到下一个片段时,我都必须要求一个确认对话框(如果我必须从这个屏幕导航是/否)。如果是,我可以移动到下一个屏幕,否则我必须关闭对话框并继续。

我有更好的 Navigation Jetpack 组件本身来处理这种情况。

我没有得到任何清晰的图片

【问题讨论】:

    标签: android android-alertdialog bottomnavigationview android-bottomnavigationview


    【解决方案1】:

    当您选择BottomNavigationView 项时,您应该使用此代码; 第一步,在onCreate中定义BottomNavigationView。

        mBtmView = (BottomNavigationView) findViewById(R.id.bottomView);
        mBtmView.setOnNavigationItemSelectedListener(this);
    

    第二步;

    @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
    
        mMenuId = item.getItemId();
    
        switch (item.getItemId()) {
            case R.id.action_food: {
    //Show dialog to there. if reject swipe from your dialog, use setCurrentItem. 
            }
            break;
            case R.id.action_medical: {
    //Show dialog to there. if reject swipe from your dialog, use setCurrentItem. 
    
            }
            break;
            case R.id.action_yoga: {
    //Show dialog to there. if reject swipe from your dialog, use setCurrentItem. 
    
            }
            break;
            case R.id.action_postures: {
    //Show dialog to there. if reject swipe from your dialog, use setCurrentItem. 
    
            }
            break;
        }
        return true;
    }
    

    【讨论】:

    • 我认为这个答案是正确的
    • 检查一下,如果有效,如果您同意我的回答,我会很高兴。
    • 这是常用的方法。
    • 普通方法可以正常使用。由于我们使用的是导航 JetPack 组件,因此 navigation.xml 应该有一个打开对话框的选项,可以使用 <fragment/>。我们也没有使用 setOnNavigationItemSelectedListener,前提是我们使用 navController、AppBarConfiguration。是否有使用 Navigation JetPack 组件的选项。
    • @Murat Çakır 即使这段代码也有一些逻辑问题。
    猜你喜欢
    • 1970-01-01
    • 2022-06-16
    • 1970-01-01
    • 2021-12-28
    • 1970-01-01
    • 2021-08-18
    • 2020-11-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多