no drawer view found with gravity RIGHT(Android实现侧滑菜单从右面滑出) 解决办法
代码如下:
<android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/colorPrimary" android:minHeight="?attr/actionBarSize"/> <android.support.v4.widget.DrawerLayout android:id="@+id/dl_home" android:layout_width="match_parent" android:layout_height="match_parent"> <FrameLayout android:id="@+id/dl_container" android:layout_width="match_parent" android:layout_height="match_parent"/> <LinearLayout android:id="@+id/dl_menu" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="end" android:background="@color/white" android:orientation="vertical"/> </android.support.v4.widget.DrawerLayout>
mToolbar = (Toolbar) findViewById(R.id.toolbar); dlHome = (DrawerLayout) findViewById(R.id.dl_home); drawerToggle = new ActionBarDrawerToggle(this, dlHome, mToolbar, 0, 0); drawerToggle.syncState();
问题描述:
使用Toolbar、DrawerLayout和ActionBarDrawerToggle实现侧滑菜单效果,按钮点击实现左侧滑出是没问题,但改成右侧滑出
报错:No drawer view found with gravity LEFT
解决办法:添加一个mToolbar菜单按钮的监听,具体实现办法如下:
mToolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (dlHome.isDrawerOpen(GravityCompat.END)) { dlHome.closeDrawers(); } else { dlHome.openDrawer(Gravity.END); } } });
问题就解决了。