我想将左上角的默认DrawerLayout图标更改为我自己的图像,但我不知道为什么它在app的加载时不起作用。仅当我打开或关闭侧边菜单时,图标才会更改。我也想禁用动画,在我更改图标后它被禁用但只有在打开和关闭后才会发生。我不知道为什么这对活动的加载不起作用
actionBar = (Toolbar) findViewById(R.id.custom_screen_toolbar);
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
drawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
drawerLayout, actionBar, R.string.drawer_open, R.string.drawer_close) {
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
actionBar.setTitle("Nav Menu Close");
actionBar.setNavigationIcon(R.drawable.action_bar_menu);
}
/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
actionBar.setTitle("Nav Menu Open");
actionBar.setNavigationIcon(R.drawable.action_bar_back_icon);
}
};
// Set the drawer toggle as the DrawerListener
drawerLayout.setDrawerListener(drawerToggle);
actionBar.setSubtitleTextColor(getResources().getColor(
R.color.light_gray));
actionBar.setBackgroundResource(R.drawable.divider_action_bar);
actionBar.setNavigationIcon(R.drawable.action_bar_menu);
setSupportActionBar(actionBar);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
答案 0 :(得分:1)
我相信调用setDisplayHomeAsUpEnabled(true)
会导致导航图标设置为后退箭头图标,此外还提供了在选择活动时完成活动的默认行为。
您应该能够删除该行并setHomeButtonEnabled(true)
以获得所需的效果。