即使在closeDrawers()之后导航抽屉也没有关闭

时间:2017-03-10 17:41:54

标签: android navigation-drawer android-navigation-drawer

我正在创建一个带导航抽屉的应用程序,用于浏览活动。

这是我的代码或抽屉

private void initInstances() {
        getSupportActionBar().setHomeButtonEnabled(true);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);


        drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
        drawerToggle = new ActionBarDrawerToggle(busr.this, drawerLayout, R.string.hello_world, R.string.hello_world);
        drawerLayout.setDrawerListener(drawerToggle);
        drawerLayout.closeDrawers();

        navigation = (NavigationView) findViewById(R.id.navigation_view);
        navigation.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(MenuItem menuItem) {
                int id = menuItem.getItemId();
                switch (id) {
                    case R.id.navigation_item_1:
                        startActivity(new Intent(busr.this, MainActivity.class));
                        break;
                    case R.id.navigation_item_2:
                        startActivity(new Intent(busr.this, aff.class));
                        break;
                    case R.id.navigation_item_3:
                        startActivity(new Intent(busr.this, webs.class));
                        break;
                    case R.id.navigation_item_4:
                        startActivity(new Intent(busr.this, admnActivity.class));
                        break;
                    case R.id.navigation_item_5:
                        startActivity(new Intent(busr.this, busr.class));
                        break;
                    case R.id.navigation_item_6:
                        startActivity(new Intent(busr.this, trng.class));
                        break;
                    case R.id.navigation_item_7:
                        startActivity(new Intent(busr.this, prospct.class));
                        break;
                    case R.id.navigation_item_8:
                        startActivity(new Intent(busr.this, erp.class));
                        break;
                    case R.id.navigation_item_9:
                        startActivity(new Intent(busr.this, result.class));
                        break;
                }
                return false;
            }
        });

1 个答案:

答案 0 :(得分:0)

试试这个:关闭drawerlayout

case R.id.navigation_item_1:
                    if (drawerLayout.isDrawerOpen(Gravity.START))
                        drawerLayout.closeDrawer(Gravity.START);
                    startActivity(new Intent(busr.this, MainActivity.class));
                    break;

case R.id.navigation_item_1:
                    drawerLayout.closeDrawers();
                    startActivity(new Intent(busr.this, MainActivity.class));
                    break;