第一步 引入
implementation'com.android.support:design:28.0.0'
第二步 创建layout文件
首先明确一点 我们新建一个activity后 通常都会有一个对应的layout文件
比如MainActivity
对应的layout文件就是activity_main.xml
接下来要做的事情就非常简单了
将activity_main.xml
改名为include_main.xml
然后新建一个xml文件 名为activity_main
这个新的activity_main.xml内容如下:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:fitsSystemWindows="true"
tools:openDrawer="start">
<!--这里将原本的main布局通过include引用回来-->
<include layout="@layout/include_main"/>
<android.support.design.widget.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--这里可以放置你想放置的任何东西 当成一个普通的布局文件即可-->
</LinearLayout>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
网友评论