no drawer view found with gravity RIGHT(Android實現側滑菜單從右面滑出) 解決辦法,drawerandroid
代碼如下:
<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); } } });
問題就解決了。