How to close navigation drawer when an item is pressed from it?
Got it!
private DrawerLayout mDrawerLayout;
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerLayout.closeDrawers();
Working perfectly fine.
Navigation Drawer closes on click
I did not realize this but the main container must come before the nav drawer. I moved the ListView for the nav drawer to the bottom of my activity_main.xml and viola, it works!
Navigation drawer force close from activity, how to fix it?
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layoutDirection="locale">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/rootView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">
<ImageButton
android:id="@+id/btn_nav"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_menu"
android:background="@android:color/transparent"
android:layout_margin="15dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/white"
app:itemIconTint="@color/white"
app:itemTextColor="@color/text_dark"
app:menu="@menu/activity_main2_drawer">
</com.google.android.material.navigation.NavigationView>
</androidx.drawerlayout.widget.DrawerLayout>
//use this code to get drawer is open or not
drawerLayout = findViewById(R.id.drawer_layout);
findViewById(R.id.btn_nav).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (drawerLayout .isDrawerOpen(GravityCompat.START)) {
drawerLayout.closeDrawer(GravityCompat.START)
} else {
drawerLayout.openDrawer(GravityCompat.START)
}
}
});
close navigation drawer after clicking on any of its item
Use closeDrawer()
method to close the drawer and start your other activity on the listener of drawer.
For Example.
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
//Start your activity
}
Issue in closing navigation drawer when click on Expendable menu item
Issue is here.
new MainActivity().closeDrawer();
Replace with
((MainActivity)mContext).closeDrawer();
You are creating the new instance of the MainActivity
every time when you click on the item. Instead of that you can cast the mContext
to the MainActivity
and call the closeDrawer()
.
Close navigation drawer after click on item?
There are a few ways you can achieve this. The simplest, in my opinion, would be to simply "watch" the $route
object from within your App.vue
:
export default {
// ...
watch: {
$route(to, from) {
this.showNav = false
}
}
}
The watch
property on the Vue instance contains functions that will watch for changes to variables of the same name. Upon change, the function is run.
More on watchers and computed properties: https://v2.vuejs.org/v2/guide/computed.html
EDIT: Some extra info about reacting to Router changes: https://router.vuejs.org/guide/essentials/dynamic-matching.html#reacting-to-params-changes
Related Topics
Java.Lang.Illegalmonitorstateexception: Object Not Locked by Thread Before Wait()
Android Import Java.Nio.File.Files; Cannot Be Resolved
Customised Listview Using Arrayadapter Class in Android
How to Create Android Virtual Device
Android Audio Fft to Retrieve Specific Frequency Magnitude Using Audiorecord
Opengl Extensions Available on Different Android Devices
Android Resource - Array of Arrays
Intellij Idea with Junit 4.7 "!!! Junit Version 3.8 or Later Expected:"
Elegant Way to Read File into Byte[] Array in Java
Difference Between Actionbarsherlock and Actionbar Compatibility
How to Give an Imageview Click Effect Like a Button on Android
When Is Onattach Called During the Fragment Lifecycle
Is There Any Library or Algorithm for Persian (Shamsi or Jalali) Calendar in Android
How to Create Your Own Library for Android Development to Be Used in Every Program You Write
How to Get Count of Number Methods Used in a Jar File
Java.Sql.Sqlexception: Column Count Doesn't Match Value Count at Row 1