Яктенс Тид Яктенс Тид - 6 months ago 68
Java Question

Android something like Navigation Drawer with custom filling

I need something like Navigation Drawer (opening with slide
gesture) to place some layout with buttons. Can you suggest me control or
technique which suite my requirements?

Answer

I think you don't need something like Navigation Drawer, but the Navigation Drawer it self. You can have a customized header in a Navigation Drawer or add a menuitems with actionLayout to add custom views to menu items.

Here is a good article from GitHub

To add a custom design for menu items;

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <item
        android:title="Refresh"
        android:id="@+id/refresh"
        app:actionLayout="@layout/menu_action_layout"
        app:showAsAction="ifRoom"/>
  </menu>

You can design menu_action_layout.xml as you wish. To access the views there in you van use;

NavigationView navigationView=(NavigationView)findViewById(idOfNavigationView);
Menu menu=navigationView.getMenu();
//take a Switch for example
SwitchCompat switch=(SwitchCompat)MenuItemCompat.getActionView(menu.findItem(R.id.menuItemId)).findViewById(R.id.actionLayoutViewId);

//work with the view
Comments