0

我需要在导航抽屉的标题中添加操作按钮。但我找不到任何好的解决方案。我需要在我的应用程序中实现此结果:

当您单击该按钮时,您应该会看到如下内容:

不幸的是,我不知道应该如何将该按钮添加到我的 xml 中。这是我的抽屉的完整标题 .xml:

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

有人知道如何轻松添加该按钮吗?

谢谢

4

1 回答 1

0

在我看来:您应该将此 XML 添加到您的 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>

您应该在 MainActivity 中将其称为:

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

    }
于 2016-08-01T03:27:55.620 回答