Ad
How To Add Buttons To Navigation Drawer Menu?
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" />
Ad
Answer
My solution is now using the MaterialDrawer Library.
I just did a quick test and it solves the problem:
Code:
...
Drawer drawer = new DrawerBuilder()
.withActivity(this)
.withToolbar(findViewById(R.id.toolbar))
.addDrawerItems(
new PrimaryDrawerItem().withName("Entry 1"),
new PrimaryDrawerItem().withName("Entry 2"),
new AbstractDrawerItem() {
@Override
public RecyclerView.ViewHolder getViewHolder(View v) {
return new RecyclerView.ViewHolder(v) {
};
}
@Override
public int getType() {
return 0;
}
@Override
public int getLayoutRes() {
return R.layout.button_a;
}
@Override
public Object withSubItems(List subItems) {
return null;
}
@Override
public Object withParent(IItem parent) {
return null;
}
},
new PrimaryDrawerItem().withName("Entry 3")
)
.build();
...
button_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"/>
Ad
source: stackoverflow.com
Related Questions
- → should I choose reactjs+f7 or f7+vue.js?
- → Phonegap Android write to sd card
- → Local reference jquery script in nanohttpd (Android)
- → Click to navigate on mobile devices
- → How to allow api access to android or ios app only(laravel)?
- → Access the Camera and CameraRoll on Android using React Native?
- → React native change listening port
- → What is the default unit of style in React Native?
- → Google play market autocomplete icon
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → Using Laravel with Genymotion
- → react native using like web-based ajax function
- → react native pdf View
Ad