Reputation: 866
I have a couple of questions about the new navigation view.
1) Scrolling the navigation view scrolls the whole view but I just want the header to stay at it's place and the navigation item to scroll.
2) To implement dividers b/w navigation items, I can do something like this:
<item
android:id="@+id/navigation_subheader"
android:title="@string/navigation_subheader">
<menu>
<item
android:id="@+id/navigation_sub_item_1"
android:icon="@drawable/ic_android"
android:title="@string/navigation_sub_item_1"/>
<item
android:id="@+id/navigation_sub_item_2"
android:icon="@drawable/ic_android"
android:title="@string/navigation_sub_item_2"/>
</menu>
</item>
But It does not work without the subheader. I tried to give it an blank string but that just leaves a vertical blank space instead of the subheader. I need the navigation item groups separated by dividers but without the subheaders.
3) Manipulating the navigation items dynamically. Before this, I used to use vertical list view as navigation item. Where I'd just set the visibility to gone of whichever navigation item I didn't want. How can I dynamically change the navigation items?
Upvotes: 4
Views: 2028
Reputation:
1) Scrolling the navigation view scrolls the whole view but I just want the >header to stay at it's place and the navigation item to scroll.
Since NavigationView is a FrameLayout we can add a ListView as a child and don't forget to delete app:menu attribute in the NavigationView then You'll get the desired behavior.
Upvotes: 0
Reputation: 363737
1) Scrolling the navigation view scrolls the whole view but I just want the >header to stay at it's place and the navigation item to scroll.
You can't obtain it with the current NavigationView
. It follows the Material guidelines. If you would like this kind of pattern you have to use a custom view.
2) To implement dividers b/w navigation items, I can do something like this:
You can use the standard NavigationView
defining a menu like this:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:id="@+id/group1" android:checkableBehavior="single" id>
//items of group1
</group>
<group android:id="@+id/group2" android:checkableBehavior="single" id>
//items of group2
</group>
</menu>
It is important to give an unique id to each group.
3) Manipulating the navigation items dynamically
You can use something like:
navigationview.getMenu().findItem(R.id.drawer_item_xxx).setVisible(xxx);
Upvotes: 5