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

  問題就解決了。




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM