How can i add the expandable list button on the ri

2019-06-06 02:30发布

问题:

I have a serious doubt. how can i add the expandable list button on the right end of the navigation drawer menu item in the android studio? for further details let me post my image... I have just edited my post...

below is my activity_main.xml

<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:id="@+id/view">

        <android.support.v7.widget.Toolbar
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:local="http://schemas.android.com/apk/res-auto"
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways"
            android:background="@color/red"
            local:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

        <android.support.design.widget.TabLayout
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:id="@+id/tabLayout"
            android:background="@color/red"
            app:tabIndicatorColor="@color/white"
            app:tabTextAppearance="@style/MyStyle"
            android:layout_below="@+id/toolbar"
            android:scrollbars="horizontal"
            android:layout_alignParentLeft="true">
        </android.support.design.widget.TabLayout>

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/viewPager">
    </android.support.v4.view.ViewPager>
</android.support.design.widget.CoordinatorLayout>

and here is my activity_navigation.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:context="com.example.goserwizz.NavigationActivity">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/AppTheme.AppBarOverlay">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

        </android.support.design.widget.AppBarLayout>

        <include layout="@layout/content_main" />

    </android.support.design.widget.CoordinatorLayout>

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

    </FrameLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_view"
        android:layout_height="match_parent"
        android:layout_width="wrap_content"
        android:layout_gravity="start"
        app:headerLayout="@layout/header"
        app:menu="@menu/menu_navigation"/>


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

And here is my menu_navigation.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <group android:checkableBehavior="single">
        <item
            android:id="@+id/Book_my_services"
            android:title="Book my services"
            android:icon="@drawable/book_my_service"/>

        <item
            android:id="@+id/My_services"
            android:title="My services"
            android:childIndicatorRight="30dp"
            android:icon="@drawable/services" />
        <item
            android:id="@+id/Add_your_vehicles"
            android:title="Add your vehicles"
            android:icon="@drawable/add_vehicle"/>
        <item
            android:id="@+id/Reschedule_slot"
            android:title="Reschedule slot"
            android:icon="@drawable/slot" />
        <item
            android:id="@+id/Cancel_services"
            android:title="Cancel services"
            android:icon="@drawable/cancel_service"/>
        <item
            android:id="@+id/history"
            android:title="History"
            android:icon="@drawable/history"/>
        <item
            android:id="@+id/Payment"
            android:title="Payment"
            android:icon="@drawable/payment"/>
    </group>
    <item android:title="HELP">
        <menu>
            <item
                android:id="@+id/Emergency_assistant"
                android:title="Emergency Assistant"
                android:icon="@drawable/emergency" />
            <item
                android:id="@+id/Call_support"
                android:title="Call support"
                android:icon="@drawable/call_support" />
            <item
                android:id="@+id/Settings"
                android:title="Settings"
                android:icon="@drawable/settings" />


        </menu>
    </item>

    <item android:title="MORE">
        <menu>
            <item
                android:id="@+id/feedback"
                android:title="Feedback"
                android:icon="@drawable/feedback" />
            <item
                android:id="@+id/How_it_works"
                android:title="How it works"
                android:icon="@drawable/how_it_work"/>
            <item
                android:id="@+id/FAQ"
                android:title="FAQ"
                android:icon="@drawable/faq"/>
            <item
                android:id="@+id/terms_and_conditions"
                android:title="Terms and conditions"
                android:icon="@drawable/terms_condition"/>
            <item
                android:id="@+id/Privacy_policy"
                android:title="Privacy policy"
                android:icon="@drawable/privacy"/>
            <item
                android:id="@+id/About"
                android:title="About"
                android:icon="@drawable/about"/>
        </menu>
    </item>
</menu>

Now,where should i make the changes so, that i can get the expandable list button on the right side of navigation menu item.

Currently my navigation drawer looks similar to this

But i need my navigation drawer like this

I need expandable list button on the right side of navigation menu item. Kindly help me ...Many thanks in advance.....

回答1:

<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_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

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

<fragment
    android:id="@+id/navigation_drawer"
    android:name="com.rooftap.adapterClass.NavigationDrawerFragment"
    android:layout_width="@dimen/navigation_drawer_width"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    tools:layout="@layout/fragment_navigation_drawer" />

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

Customize your fragment_navigation_drawer.xml layout add spinners or whatever you want like how we do in normal layout and create a NavigationDrawerFragment.class for actions. don't use android.support.design.widget.NavigationView.