如何在android中打开导航抽屉,如下图所示

时间:2018-06-02 06:27:01

标签: android navigation-drawer drawer

自定义android中的默认导航抽屉,如下图或从底部开始

screenshot

2 个答案:

答案 0 :(得分:0)

这是主要的活动布局

<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".NavigationDrawerExample">


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:text="Content" />

</LinearLayout>

<android.support.design.widget.NavigationView
    android:layout_width="250dp"
    android:background="@android:color/transparent"
    android:layout_height="match_parent"
    android:layout_gravity="start">

    <include layout="@layout/nav_view" />

</android.support.design.widget.NavigationView>

这是navigationview.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:gravity="bottom"
android:background="@android:color/transparent"
android:orientation="vertical">

<android.support.v7.widget.CardView
    app:cardElevation="5dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

 <LinearLayout
     android:gravity="center"
     android:orientation="vertical"
     android:layout_width="match_parent"
     android:layout_height="wrap_content">

     <ImageView
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:src="@mipmap/ic_launcher" />

     <TextView
         android:padding="16dp"
         android:text="One"
         android:layout_width="match_parent"
         android:layout_height="wrap_content" />
     <TextView
         android:padding="16dp"
         android:text="One"
         android:layout_width="match_parent"
         android:layout_height="wrap_content" />
     <TextView
         android:padding="16dp"
         android:text="One"
         android:layout_width="match_parent"
         android:layout_height="wrap_content" />
     <TextView
         android:padding="16dp"
         android:text="One"
         android:layout_width="match_parent"
         android:layout_height="wrap_content" />

 </LinearLayout>
</android.support.v7.widget.CardView>

答案 1 :(得分:0)

您需要使用 SlidingRootNav 使用此库

compile 'com.yarolegovich:sliding-root-nav:1.1.0'

以下是参考https://github.com/yarolegovich/SlidingRootNav

    new SlidingRootNavBuilder(this)
    .withMenuLayout(R.layout.menu_left_drawer)
    .inject();