Been looking for ways to disable the default clickable header layout in NavigationView
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/drawer_header"
app:menu="#menu/drawer_view" />
Tried to do clickable=false in the NavigationView but it didn't work.
I also tried setClickable(false) programmatically didn't work either.
try android:enabled="false" if available for NavigationView.
Found a way to do it by inflating it in Java instead of XML.
navigationView.inflateHeaderView(R.layout.drawer_header);
the navigationView has a listview in it. reference the listview programatically. then add your own header and turn off selection on the header. to turn off selection of header use:
listview.addHeaderView(myheaderView,null,false);
Related
sorry for my bad English.
I have a navigation drawer in some activities, I want the icon of each navigation view item to be placed to the right of that item's text and the whole item get right gravity.
Because I only used Persian in my app, I can not use "supportsRtl" in my code, if I use, it will look weird when I set device language to any rtl languages.
I think probably I can fix this with setting custom layout for navigation view, but I'm looking for a simpler way. this is my NavigationView XML code:
<android.support.design.widget.NavigationView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:menu="#menu/menu"
android:layout_gravity="end" />
Edited :
layoutDirection is a good answer but i used drawerLayout.openDrawer(GravityCompat.START);
for opening navigation drawer. now if device language be an rtl language this make app crash.
Make supportsRtl true and set the layout dirction to RTL on navigation View and LTR in other layouts
Just add android:layoutDirection="rtl" to your NavigationView, like this:
<android.support.design.widget.NavigationView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:menu="#menu/menu"
android:layoutDirection="rtl"
android:layout_gravity="end" />
I have a Nav Drawer where the header has a ListView, and the body is a standard menu. I have two implementations of this, each one with its own problem
The drawer should look like this: (white square is the ListView)
The 1st implementation shows both views but doesn't allow scrolling of the ListView in the header. Any scrolling is "intercepted" by the nav Drawer
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_drawer" //contains my listView
app:menu="#menu/activity_drawer_main" >
</android.support.design.widget.NavigationView>
In the 2nd implementation, I fixed the scrolling issue by includeing the header separately in the navView. It scrolls, but now the menu list is gone. It doesn't show at all.
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:menu="#menu/activity_drawer_main" >
<include
layout="#layout/nav_header_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.design.widget.NavigationView>
The drawer should look like the image above, but implementation 1 (pictured) won't scroll, and implementation two doesn't have the menu items (share, send).
Any help figuring out how to fix either implementation is appreciated!
Note: I know I could create a LinearLayout of items in place of the menu, but it doesn't look as nice, with the graying out when tapped. I could code that as well, but I feel like the functionality is built in, (I just can't access it), so why build it from scratch?
I found out how to override the navigation view's intercepting the listview's scroll here https://stackoverflow.com/a/14577399/5202215
I use NavigationView to create a Left slide menu. But i want the menu remain in Left position on few px (100-150dp) . I've try to play with margin, padding, searching google sample code, but no results.
There's a solution ?
Thx,
try this...set width of your navigation
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/drawer_header"
app:itemBackground="#drawable/back_color"
app:menu="#menu/nav_drawer_menu"/>
I have made an Activity with RelativeLayout and has been set well. Now as per the new requirement I have to add a navigation drawer to top left corner. How can I proceed further? Please anyone explain briefly.
I suggest you to use NavigationView to create your drawer. All you need to do is just to wrap your current RelativeLayout in the DrawerLayout and add the NavigationView
<android.support.v4.widget.DrawerLayout>
<RelativeLayout>
<android.support.v7.widget.Toolbar />
</RelativeLayout>
<android.support.design.widget.NavigationView
android:layout_gravity="start"
app:menu="#menu/drawer" />
</android.support.v4.widget.DrawerLayout>
Note you have to create your menu under res/menu/drawer.xml. You alsou should use AppCompatActivity and set your Toolbar with setSupportActionBar().
This is relatively good tutorial. This one is even more detailed.
I wanted to set the background color of my Navigation drawer in java but it seems as setBackgroundColor and all similar methods have no effect.
Only the XML line android:background="#color/mycolor" is working. If remove the xml line and try one of the methods the drawer just stays transparent.
Any ideas?
In your activity_main.xml include the following
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/navigation_drawer_header"
app:menu="#menu/menu_drawer"
android:background="#color/color_navigation_list_background"
app:itemIconTint="#color/color_selector_navigation_item"
app:itemTextColor="#color/color_selector_navigation_item"/>
I just solved my own problem.
I totally forgot that it's not the DrawerLayout I want to set the background to, but the ListView inside.
I admit I made it somewhat hard for you guys without adding code to my post -.-'
So instead of:
private DrawerLayout mDrawerLayout;
(...)
mDrawerLayout.setBackgroundResource(int);
I had to do this:
private ListView mDrawerList;
(...)
mDrawerList.setBackgroundResource(int);
cast your navigation drawer to navigationView and do as follows
navigationView.setBackgroundColor(getResources().getColor(R.color.colorPrimaryDark));