DrawerLayout在给右边drawer添加点击事件,会和actionBarDrawerToggle冲突
澳门银河官网
澳门银河官网
当前位置 : 澳门银河官网 > 澳门银河官网下载

DrawerLayout在给右边drawer添加点击事件,会和actionBarDrawerToggle冲突

  1. 描述你的问题

DrawerLayout在给右边drawer添加点击事件,会和actionBarDrawerToggle冲突,是不是actionBarDrawerToggle关联了左右两边的监听,所以,当我给右边添加点击弹出事件的时候,toggle的图标也跟着改变。而这个syncState是处理这个图标的。

请问怎么取消actionBarDrawerToggle对右边drawer的影响?

如果我把syncState去掉,则何不影响,但是左边的drawer就没有了actionBar的图标了呀?

怎么解决

  1. 贴上相关代码

我的代码:

public class MainActivity extends AppCompatActivity {

    private Toolbar toolbar = null;
    private DrawerLayout drawerLayout;
    private int existTime = 0;
    private boolean rightToggle;
    private ActionBarDrawerToggle toggle;

    @Override
    protected void onCreateBundle savedInstanceState {
        super.onCreatesavedInstanceState;
        setContentViewR.layout.activity_main;
        initView;

        setSupportActionBartoolbar;

         toggle = new ActionBarDrawerTogglethis,drawerLayout, toolbar, R.string.open, R.string.close;
        
        toggle.syncState;
        
        drawerLayout.setDrawerListenertoggle;
    }

    @Override
    public boolean onKeyDownint keyCode, KeyEvent event {

        if keyCode == KeyEvent.KEYCODE_BACK {

            if System.currentTimeMillis - existTime > 2000 {

                Toast.makeTextMainActivity.this, "click one more time to exist", Toast.LENGTH_SHORT.show;
                return true;
            } else {

                finish;
                System.exit0;
            }
        }


        return super.onKeyDownkeyCode, event;
    }

    private void initView {

        toolbar = Toolbar findViewByIdR.id.toolBar;
        drawerLayout = DrawerLayout findViewByIdR.id.drawer;
    }

    @Override
    public boolean onCreateOptionsMenuMenu menu {

        getMenuInflater.inflateR.menu.menu, menu;

        return true;
    }

    @Override
    public boolean onOptionsItemSelectedMenuItem item {

        switch item.getItemId {
            case R.id.netWork:

                if drawerLayout.isDrawerOpenGravityCompat.END{

                    rightToggle = true;
                }
                if rightToggle {

                    drawerLayout.closeDrawerGravityCompat.END;
                    rightToggle = false;
                } else {

                    drawerLayout.openDrawerGravityCompat.END;
                    drawerLayout.closeDrawerGravityCompat.START;
                    rightToggle = true;
                }


        }

        return true;
    }
}
  1. 贴上相关截图
    看我点右边的drawer,actionbar的图标变成了箭头....

  1. 已经尝试过哪些方法仍然没解决(附上相关链接)

广告位

澳门银河官网