我正在尝试实施DrawerLayout
。抽屉布局工作正常。但左上角显示的图标为android.R.id.home
。但是我在ActionBarDrawerToggle
中提到了我的自定义图标,如下所示:
// Getting reference to the DrawerLayout
drawerLayout = (android.support.v4.widget.DrawerLayout) findViewById(R.id.drawer_layout);
drawerList = (ListView) findViewById(R.id.drawer_list);
// Getting reference to the ActionBarDrawerToggle
drawerToggle = new ActionBarDrawerToggle(this, drawerLayout,
**R.drawable.icon_top_menu**, R.string.drawer_open,
R.string.drawer_close) {
/** Called when drawer is closed */
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
}
/** Called when a drawer is opened */
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
}
};
// Setting DrawerToggle on DrawerLayout
drawerLayout.setDrawerListener(drawerToggle);
getActionBar().setIcon(R.drawable.icon_top_menu);
// enabling action bar app icon and behaving it as toggle button
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
有什么问题?
答案 0 :(得分:0)
你应该检查你选择的onoptionsItem,那里应该丢失...............
如下图所示:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
代替'.action_settings'尝试'icon_top_menu'你的偶像.......
答案 1 :(得分:0)
您应该在每个要显示图标的活动中使用图标菜单的可见性true / false ...并且请正确描述您想要做的问题。
答案 2 :(得分:0)
要 user1182217
好吧,我得到了你的问题,希望这会对你有帮助。
至于您正在使用的图标ID" android.R.id.home"这是' android id'默认情况下, 代替那个使用你的图标id为R.id.home / R.id.your_icon_id希望唯一的错误为 根据你的问题描述..........