0

I need to add action button to header of my navigation drawer. But I cant find any good solution for that. I need to achieve this result in my app:

When you clicked that button you should see something like this:

Unfortunatelly i dont know how should i add that button to my xml. Here is the complete header .xml for my drawer:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="280dp"
    android:layout_height="240dp"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/drawer_header_layout"
        android:layout_width="280dp"
        android:layout_height="168dp"
        android:background="@drawable/placeholder"
        android:gravity="bottom"
        android:orientation="vertical"
        android:theme="@style/ThemeOverlay.AppCompat.Dark">

        <ImageView
            android:id="@+id/drawer_header_image"
            android:layout_width="64dp"
            android:layout_height="64dp"
            android:layout_marginBottom="8dp"
            android:layout_marginLeft="16dp"
            android:layout_marginStart="16dp"
            android:layout_marginTop="43dp"
            android:contentDescription="null"
            android:scaleType="centerCrop"
            tools:src="@drawable/avatar_circle" />

        <TextView
            android:id="@+id/drawer_header_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="3dp"
            android:layout_marginLeft="16dp"
            android:layout_marginStart="16dp"
            android:textAppearance="@style/TextAppearance.AppCompat.Body1"
            android:textColor="@color/bodyTextColor"
            android:textStyle="bold"
            tools:text="Elizabeth Cray" />

        <TextView
            android:id="@+id/drawer_header_email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="9dp"
            android:layout_marginLeft="16dp"
            android:layout_marginStart="16dp"
            android:textAppearance="@style/TextAppearance.AppCompat.Body1"
            tools:text="liz@gmail.com"
            />

</LinearLayout>

Is there somebody who knows how to easily add that button?

Thanks

Community
  • 1
  • 1
Tom Wayne
  • 1,288
  • 1
  • 12
  • 31
  • You should be able to add another ImageView with the overflow icon. However, I have never seen that UX pattern in an app. Typically, you add an additional action after some margin within the list of the NavigationView – OneCricketeer Aug 01 '16 at 08:17
  • I think that is a ImageButton with that icon as source, placed in the layout that's been using as the header of the navigation. – Alejandro Cumpa Aug 01 '16 at 08:19

1 Answers1

0

In my opinion: you should add this XML to your res-main

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
    android:id="@+id/miCompose"
    android:icon="@drawable/male_profile"
    app:showAsAction="ifRoom"
    android:title="Your Image ">
</item>

 </menu>

And you should call this in MainActivity as:

   @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;

    }
Niroj
  • 1,114
  • 6
  • 29