1 回答
TA贡献1946条经验 获得超3个赞
用下面替换您的导航视图
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header"
app:menu="@menu/my_menu">
</android.support.design.widget.NavigationView>
添加以下方法以显示切换
public void addToggel() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
//drawer.setDrawerListener(toggle);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
}
在 string.xml 中添加以下字符串
<string name="navigation_drawer_open">open</string>
<string name="navigation_drawer_close">close</string>
根据您的代码更新抽屉布局 ID 和导航视图 ID
让我知道更多帮助
添加回答
举报