gpt4 book ai didi

Android - actionBar.setDisplayHomeAsUpEnabled 问题

转载 作者:太空宇宙 更新时间:2023-11-03 11:31:07 25 4
gpt4 key购买 nike

在我扩展 SherlockFragmentActivity 的 Activity 中,我有操作栏并且还设置了 actionBar.setDisplayHomeAsUpEnabled(true) 以返回到我之前的 Activity 。一切正常。但是当我点击主页按钮时,背景颜色应该只应用于应用程序图标,但它也适用于操作栏上的“标题”,如屏幕截图所示。我不希望这发生。当我点击主页按钮时,只有应用程序图标应该可以点击(背景颜色应该只应用于应用程序图标)而不是标题。知道我该怎么做吗?

enter image description here

我的 Activity 代码:

ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(some_string);

最佳答案

不要忘记这部分,因为主页按钮也是一个菜单按钮。

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// This is called when the Home (Up) button is pressed in the action bar.
// Create a simple intent that starts the hierarchical parent activity and
// use NavUtils in the Support Package to ensure proper handling of Up.
Intent upIntent = new Intent(this, MainActivity.class);
if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
// This activity is not part of the application's task, so create a new task
// with a synthesized back stack.
TaskStackBuilder.from(this)
// If there are ancestor activities, they should be added here.
.addNextIntent(upIntent)
.startActivities();
finish();
} else {
// This activity is part of the application's task, so simply
// navigate up to the hierarchical parent activity.
NavUtils.navigateUpTo(this, upIntent);
}
return true;
}
return super.onOptionsItemSelected(item);
}

关于Android - actionBar.setDisplayHomeAsUpEnabled 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15173199/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com