I want to add a button to my navigation drawer menu, like so:
desired result:
I tried achieving this using the actionLayout parameter, but I seem to only be able to use some space on the right, not the entire width:
current result:
The title seems to be occupying the space on the left. But I want to add a button with full width like in the first picture.
My current code:
...
<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" />
Action view in drawers intended to show this "small" addition view on the right of the menu item, so it'll be restricted in size.
You can add desired button as some sort of footer like following:
<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>
Note that you can put everything you want as a child, if you want some more views - just add LinearLayout
there and put all additional views as children of it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With