Is it possible to add Offset in NavigationView android? - android

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"/>

Related

how to make hamburger menu fully visible

by default half of hamburger is shown, as seen at the top left corner of the screenshot. I want to display full hamburger. code is taken from https://developer.android.com/training/implementing-navigation/nav-drawer.html. how can I do this?
Seems you are using very old technique to create Navigation Drawer. Its around 4 years old code and seems perfect regarding old version.
FYI, previously this kind of UI was done using DrawerLayout with ListView. But now android itself officially introduced sliding panel menu by introducing a newer concept called Navigation Drawer in which we combine DrawerLayout and NavigationView to achieve the desired output.
How to make hamburger menu fully visible?
SOLUTION:
Use AppCompatActivity instead of Activity and use AppCompat theme to achieve your desired output.
Use NavigationView instead of ListView.
Here is an example of NavigationView:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<!-- Your contents -->
<android.support.design.widget.NavigationView
android:id="#+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="#menu/my_navigation_items" />
</android.support.v4.widget.DrawerLayout>
Here is a very good tutorial: Android Sliding Menu using Navigation Drawer
Hope this will help~

ListView in NavigationView not scrolling / NavigationView Menu Disappearing

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

Custom NavigationDrawer with full image as a background

I can't find solution for implementing very custom NavigationDrawer. I want it to have one image background (black one with white square) with few items like in the picture below:
Can it be made? As far as I read, it's not really what SDK supports. Only what I got to is that making two items in one line is achievable (still searching for solutions, tho).
BNK answer was the best one:
<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_main"
app:menu="#menu/activity_main_drawer"
android:background="#drawable/ic_action_android"/>

Navigation bar in relative layout (Android App)

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.

Is it possible to disable the clickable HeaderLayout in NavigationView?

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);

Categories

Resources