Girish Girish - 20 days ago 5
Android Question

How to hide NavigationView ? android:visibility="gone" is not working

I am using 2 ( Left and Right ) NavigationView for my app, and want to show right NavigationView for certain conditions only. Hence set its visibility to "GONE" in layout file and will make it visible when it is needed. However even after making it "GONE" right NavigationView keep showing up.

Any thoughts how to hide it ?




<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<com.example.girishkhatri.tt0401.NavigationViewRight
android:id="@+id/nav_right_view"
android:layout_width="wrap_content"
android:layout_height="600dp"
android:layout_marginTop="80dp"
android:layout_gravity="right"
android:fitsSystemWindows="true"
android:visibility="gone" //not working as expected
app:itemBackground="@drawable/nav_item_selector"
app:headerLayout="@layout/nav_header_right"
app:menu="@menu/activity_right_drawer" />



Answer

If you want to prevent the user from opening the drawer and you want to show it in special circumstance, it's better to use lock and unlock for the drawer.

Put a listener for the drawer and in its OnDrawerClosed, Lock it again.

Whenever you should show the drawer, unlock it first and then call open on it