Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

android - no more allow open Drawer layout from right side in navigation drawer

I want to open drawer from right side, but when swite it works but when i click on toggle button in action bar it force close and give error that "No drawer view found with gravity LEFT"

please help...

I add layout like

 <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"

   />

Error:

 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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

i have same issue, and i fix it bellow:

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);
        }
    }
});

yes, it's work, i'm fix this bug in 5hour :( but i'm very happy when resolve it. ^^ thanks & good luck


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...