我有一個使用抽屜佈局和適配器製作的導航抽屜。我想在側邊菜單的底部添加一個註銷按鈕。我經歷過,但無法解決。主要的xml文件在抽屜佈局中有一個列表視圖。將按鈕添加到導航抽屜列表的頁腳android
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="5"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.5"></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:layout_gravity="center"
android:orientation="vertical">
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/buttonbackground"
android:text="PHOTOS"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
android:textColor="@color/white" />
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="@drawable/buttonbackground"
android:text="VIDEOS"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
android:textColor="@color/white" />
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="@drawable/buttonbackground"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
android:text="HISTORY"
android:textColor="@color/white" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.5"></LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/navList"
android:layout_width="320dp"
android:layout_height="match_parent"
android:layout_above="@+id/logout"
android:layout_gravity="left|start"
android:background="#ffeeeeee"></ListView>
<Button
android:id="@+id/logout"
android:layout_width="320dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="LogOut" />
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
<android.support.v4.widget.DrawerLayout/>
而且這個列表在java代碼中被誇大了。
private void addDrawerItems() {
String items[]={"Home","Video","Camera","History","Version"};
mAdapter=new ArrayAdapter<>(this,R.layout.listview_drawer_item_row,items);
mDrawerList.setAdapter(mAdapter);
}
如何在菜單底部添加按鈕?
創建一個自定義的佈局和充氣佈局到您的抽屜 –
我相信佈局將是每行不?不知道 – Harshita
@Harshita檢查此鏈接https://stackoverflow.com/questions/21796209/how-to-create-a-custom-navigation-drawer-in-android –