我进行了一些搜索并尝试了许多解决方案,但是我要解决同样的问题:
直到我轻拂抽屉,抽屉汉堡包图标才会显示。
这是我的代码
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
setSupportActionBar(toolbar);
setupDrawer();
...
}
//calling the method bellow inside onCreate
public void setupDrawer(){
mDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close){
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
syncState();
}
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
syncState();
}
};
mDrawerToggle.setDrawerIndicatorEnabled(true);
drawerLayout.setDrawerListener(mDrawerToggle);
ActionBar actionBar = getActionBar();
if(actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setIcon(R.drawable.ic_launcher);
}
}
我希望它能显示出来。
尝试通过getSupportActionBar()方法而不是getActionBar()获取操作栏。在setupDrawer()方法内部:
mDrawerToggle.setDrawerIndicatorEnabled(true);
drawerLayout.setDrawerListener(mDrawerToggle);
// here
//ActionBar actionBar = getActionBar();
ActionBar actionBar = getSupportActionBar();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句