Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm building an app where I want to show some additional information in the navigation drawer but after clicking inside of the navigation drawer it closes by default and I would like it to remain open till the user click outside the navigation drawer or presses the back button

Is this possible? And how do I implement it ? If not how else can I implement it without using the navigation view

I have tried using: mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN); In my onCreate and onNavigationItemSelected ...Using it on the onCreate opens up the navigation drawer by default leaving me unable to close it

This is my drawer listener code;

DrawerLayout   drawer = findViewById(R.id.drawer_layout);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
321 views
Welcome To Ask or Share your Answers For Others

1 Answer

    DrawerLayout drawerLayout; // Global variable

    drawerLayout = findViewById(R.id.drawer_layout);
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.addDrawerListener(toggle);
        toggle.syncState();


        drawerLayout.openDrawer(GravityCompat.START); // Use this line of code where you want to keep open the drawerLayout. 

If you still have problem to understand please let me know.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...