2016-07-31 42 views
0

Ich muss der Kopfzeile meiner Navigationsleiste Aktionsschaltfläche hinzufügen. Aber dafür kann ich keine gute Lösung finden. Ich brauche dieses Ergebnis in meiner app zu erreichen:So fügen Sie dem Material NavigationDrawer-Header eine Aktionsschaltfläche hinzu

Wenn Sie die Schaltfläche geklickt Sie etwas sehen sollte:

Unfortunatelly ich weiß nicht, wie soll ich diese Schaltfläche hinzufügen zu meinem XML. Dies ist der komplette Kopf .xml für meine Schublade:

<?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="[email protected]" 
      /> 

</LinearLayout> 

Gibt es jemanden, der weiß, wie man leicht auf diese Schaltfläche hinzufügen?

Dank

+0

Sie sollten fähig sein: Sie diese XML in Ihre res-Haupt

<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> 

Und Sie sollten dies nennen in MainActivity wie sollte hinzufügen um ein weiteres ImageView mit dem Überlaufsymbol hinzuzufügen. Allerdings habe ich dieses UX-Muster noch nie in einer App gesehen. In der Regel fügen Sie nach einem gewissen Abstand innerhalb der Liste der NavigationView eine weitere Aktion hinzu. –

+0

Ich denke, dass ein ImageButton mit diesem Symbol als Quelle im Layout platziert ist, das als Überschrift der Navigation verwendet wurde. – Aiapaec

Antwort

0

Meiner Meinung nach:

@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; 

    } 
+1

Wird dies nicht zur Symbolleiste hinzugefügt, nicht zur NavigationView? –

+0

Ja, aber ich denke, das könnte einfacher und einfacher sein, die diesem Beitrag helfen könnte. – Niroj

+0

Während ich insgesamt zustimme, beantwortet es nicht wirklich die Frage, wo es heißt: * Ich muss der Kopfzeile meiner Navigationsschublade Aktionsschaltfläche hinzufügen * –