描述你的问题
DrawerLayout在给右边drawer添加点击事件,会和actionBarDrawerToggle冲突,是不是actionBarDrawerToggle关联了左右两边的监听,所以,当我给右边添加点击弹出事件的时候,toggle的图标也跟着改变。而这个syncState是处理这个图标的。
请问怎么取消actionBarDrawerToggle对右边drawer的影响?
如果我把syncState去掉,则何不影响,但是左边的drawer就没有了actionBar的图标了呀?
怎么解决
贴上相关代码
我的代码:
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 onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
setSupportActionBar(toolbar);
toggle = new ActionBarDrawerToggle(this,drawerLayout, toolbar, R.string.open, R.string.close);
toggle.syncState();
drawerLayout.setDrawerListener(toggle);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (System.currentTimeMillis() - existTime > 2000) {
Toast.makeText(MainActivity.this, "click one more time to exist", Toast.LENGTH_SHORT).show();
return true;
} else {
finish();
System.exit(0);
}
}
return super.onKeyDown(keyCode, event);
}
private void initView() {
toolbar = (Toolbar) findViewById(R.id.toolBar);
drawerLayout = (DrawerLayout) findViewById(R.id.drawer);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.netWork:
if (drawerLayout.isDrawerOpen(GravityCompat.END)){
rightToggle = true;
}
if (rightToggle) {
drawerLayout.closeDrawer(GravityCompat.END);
rightToggle = false;
} else {
drawerLayout.openDrawer(GravityCompat.END);
drawerLayout.closeDrawer(GravityCompat.START);
rightToggle = true;
}
}
return true;
}
}
贴上相关截图
看我点右边的drawer,actionbar的图标变成了箭头....
已经尝试过哪些方法仍然没解决(附上相关链接)