在导航栏上加载popupWIndow(弹出窗口覆盖导航栏)

时间:2019-06-03 13:11:24

标签: java android android-layout android-fragments

我试图弄清楚如何加载弹出窗口,并使用片段加载到导航抽屉上。

到目前为止,我只能弄清楚如何加载弹出窗口,但是导航抽屉将在弹出窗口出现时关闭,但是我希望在弹出窗口出现时将导航抽屉留在后台。

谢谢。

此外,该片段目前只是黑色片段,除了更改背景颜色外,我没有添加任何其他内容。

    public boolean onNavigationItemSelected(MenuItem item) {

        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);

        int width = dm.widthPixels;
        int height = dm.heightPixels;
        // Handle navigation view item clicks here.
        int id = item.getItemId();

        if (id == R.id.nav_home) {
            android.support.v4.app.FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            ft.replace(R.id.flMain, new HomeFragment());
            ft.commit();
        }
        else if (id == R.id.nav_profile) {
            android.support.v4.app.FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            ft.replace(R.id.flMain, new ProfileFragment());
            ft.commit();
        }
        else if (id == R.id.nav_post_ad) {
            android.support.v4.app.FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            ft.replace(R.id.flMain, new PostAdFragment());
            ft.commit();
        }
        else if (id == R.id.nav_sign_in) {
            Intent signInIntent = new Intent(MainActivity.this, com.bookswap.ui.login.LoginActivity.class);
            startActivity(signInIntent);
        }
        else if (id == R.id.nav_sign_out) {
            //TODO:
            //load pop-up page to confirm sign out
            //startActivity(new Intent(MainActivity.this, confirmSignOut.class));
            LayoutInflater inflater = (LayoutInflater) MainActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View layout = inflater.inflate(R.layout.fragment_confirm_sign_out, null);
            PopupWindow popupWindow = new PopupWindow(layout, (int)(width * 0.8), (int)(height * 0.8), true);
            //popupWindow.setOutsideTouchable(true);
            //popupWindow.getOverlapAnchor(true);
            popupWindow.setFocusable(true);
            popupWindow.showAtLocation(layout, Gravity.CENTER,0,0);
        }

        DrawerLayout drawer = findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }

0 个答案:

没有答案