Android 如何将按钮添加到导航抽屉菜单?

Android 如何将按钮添加到导航抽屉菜单?,android,layout,menu,navigation-drawer,Android,Layout,Menu,Navigation Drawer,我想在导航抽屉菜单中添加一个按钮,如下所示: 所需结果: 我尝试使用actionLayout参数实现这一点,但我似乎只能使用右侧的一些空间,而不能使用整个宽度: 当前结果: 标题似乎占据了左边的空间。 但我想添加一个全宽按钮,如第一张图片所示 我当前的代码: ... <item android:id="@+id/nav_login" android:title=""

我想在导航抽屉菜单中添加一个按钮,如下所示:

所需结果

我尝试使用actionLayout参数实现这一点,但我似乎只能使用右侧的一些空间,而不能使用整个宽度:

当前结果

标题似乎占据了左边的空间。 但我想添加一个全宽按钮,如第一张图片所示

我当前的代码:

...

<item
                    android:id="@+id/nav_login"
                    android:title=""
                    app:actionLayout="@layout/button_login"
                    app:showAsAction="ifRoom"/>

...
。。。
...
button_login.xml

<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:background="#0000ff"
    android:text="Login"
    android:textColor="#ffffff"
    android:layout_height="match_parent" />

抽屉中的操作视图用于在菜单项右侧显示此“小”添加视图,因此其大小受到限制

您可以添加所需的按钮作为某种页脚,如下所示:

<android.support.design.widget.NavigationView
    android:id="@+id/drawer"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:menu="@menu/drawer">
    <Button
       android:id="@+id/footer_item_1"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:layout_gravity="bottom"
       android:text="Footer Button 1" />
</android.support.design.widget.NavigationView>


请注意,如果您想要更多视图,您可以将所需的一切都作为子视图放置—只需在此处添加
LinearLayout
,并将所有其他视图作为子视图放置。

我的解决方案现在使用

我刚刚做了一个快速测试,它解决了问题:

代码:

按钮a.xml

<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        android:layout_width="match_parent"
        android:text="Login"
        android:layout_height="50dp"/>

谢谢。但我不想将按钮用作页脚,而是将其用作菜单中的常规项。
<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        android:layout_width="match_parent"
        android:text="Login"
        android:layout_height="50dp"/>