我想从右侧打开抽屉,但是当它打开它有效但是当我点击操作栏中的切换按钮时它会强制关闭并给出错误" 没有抽屉视图发现重力LEFT "
请帮忙......
我添加了像
这样的布局 <ListView
android:layout_gravity="right|end"
android:id="@+id/left_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:divider="#ccc"
android:dividerHeight="1dp"
/>
错误:
java.lang.IllegalArgumentException: No drawer view found with gravity LEFT
at android.support.v4.widget.DrawerLayout.openDrawer(DrawerLayout.java:1319)
at android.support.v7.app.ActionBarDrawerToggle.toggle(ActionBarDrawerToggle.java:290)
at android.support.v7.app.ActionBarDrawerToggle.access$100(ActionBarDrawerToggle.java:64)
at android.support.v7.app.ActionBarDrawerToggle$1.onClick(ActionBarDrawerToggle.java:200)
at android.view.View.performClick(View.java:4084)
at android.view.View$PerformClick.run(View.java:16966)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:6)
我有同样的问题,我会解决它:
toolbar = (Toolbar) findViewById(R.id.tool_bar);
Drawer = (DrawerLayout) findViewById(R.id.DrawerLayout);
mDrawerToggle = new ActionBarDrawerToggle(this,Drawer,toolbar,R.string.openDrawer,R.string.closeDrawer){
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
}
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
}
}; // Drawer Toggle Object Made
Drawer.setDrawerListener(mDrawerToggle);
mDrawerToggle.syncState();
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (Drawer.isDrawerOpen(Gravity.RIGHT)) {
Drawer.closeDrawer(Gravity.RIGHT);
} else {
Drawer.openDrawer(Gravity.RIGHT);
}
}
});
是的,这是工作,我在5小时内解决了这个问题:(但是我很高兴解决它。^^ 谢谢&amp;祝你好运