Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a dropdown within a Navigation Drawer (in Android)?

I would like to be a able to create a Navigation Drawer that has some expandable, selectable items, and some non-expandable items. The consensus on StackOverflow for questions similar to mine point to solutions by ExpandableListView (which may not even apply to my idea). For the most part, what people are asking for is a way to separate items in the Nav Drawer like the GMail app does with labels, not what I'm trying to do...

...which is essentially outlined HERE enter image description here

and SIMILARLY HERE (though all, not some are dropdowns) . And not like THIS ANSWER.

like image 772
AlleyOOP Avatar asked Mar 15 '15 23:03

AlleyOOP


People also ask

How to create a custom navigation drawer in Android</strong>?

How to create a custom navigation drawer in Android? This example demonstrate about How to resize Image in Android App. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml.

How to use navigationdrawer option in Android?

It will appear when the user pulls it like a drawer. This drop-down menu has a Header or a Menu. Of course, it should be noted that the NavigationDrawer option has been introduced by the Android operating system and can be easily used by using the Design Support library.

How to create a dropdown menu in a navigation bar?

How TO - Dropdown Navbar 1 Dropdown Menu in Navbar. Hover over the "Dropdown" link to see the dropdown menu. 2 Create A Dropdown Navbar. Create a dropdown menu that appears when the user moves the mouse over an element inside a navigation bar. 3 Clickable Dropdown in Navbar. Click on the "Dropdown" link to see the dropdown menu. ...

How to add navigation header in Android Studio?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to res/layout/nav_header_main.xml.


1 Answers

Use an ExpandableListView within a DrawerLayout, like so:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout2"
android:layout_width="match_parent"
android:layout_height="match_parent">

<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/tv_commentary_behind_nav"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal|top"
        android:text="Frame text" />
</FrameLayout>
<!-- The navigation drawer -->
    <ExpandableListView
        android:id="@+id/left_drawer2"
        android:layout_width="250dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/white"
        android:choiceMode="multipleChoice"
        android:dividerHeight="0dp"
        />

</android.support.v4.widget.DrawerLayout>

Then initialize in code like so:

    private DrawerLayout drawer;
    private ExpandableListView drawerList;
    private CheckBox checkBox;
    private ActionBarDrawerToggle actionBarDrawerToggle;


@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.drawer_layout);
        drawer = (DrawerLayout) findViewById(R.id.drawer_layout2);
        drawerList = (ExpandableListView) findViewById(R.id.left_drawer2);
        drawerList.setAdapter(new NewAdapter(this, groupItem, childItem));
    }
like image 60
AlleyOOP Avatar answered Sep 30 '22 07:09

AlleyOOP