AndroidStudio之侧滑菜单实现
基本侧滑菜单实现:
1.去掉系统自带的ActionBar
1.修改MainActivity默认的Style,在values/styles.xml中修改style为:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
2.设置界面的布局
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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:id="@+id/drawerlayout_drawer">
<!--DrawerLayout最好为界面的根布局-->
<!--主内容区的布局代码要放在侧滑菜单布局的前面,-->
<RelativeLayout
android:id="@+id/drawerlayout_main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/drawer_layout_rl_toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/ac