当我尝试在滑动操作时显示导航抽屉时,有时它不会打开(您可以在链接的屏幕截图中看到它),当我慢慢滑动时它出现的频率更高。它也出现在 google 提供的应用程序示例中。
MenuActivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// Burger button
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);
toggle.syncState();
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
// Getting navigation view from activity_menu.xml
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
// Getting Navigation Header resources
View headerLayout = navigationView.getHeaderView(0);
emailTextViewNavHeader = (TextView) headerLayout.findViewById(R.id.textViewEmailNavHeaderMenu);
nameTextViewNavHeader = (TextView) headerLayout.findViewById(R.id.textViewNameNavHeaderMenu);
imageViewProfileNavHeader = (CircularImageView) headerLayout.findViewById(R.id.imageViewProfileNavHeaderMenu);
this.setViewResources();
this.fillInReflexionMenuList();
}
活动菜单.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start"
android:background="#555555">
<include
android:id="@+id/main"
layout="@layout/app_bar_menu"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_menu"
app:menu="@menu/activity_menu_drawer" />
</android.support.v4.widget.DrawerLayout>