gpt4 book ai didi

android - 尝试更改 ActionBar homeAsUp 按钮的颜色

转载 作者:行者123 更新时间:2023-11-30 01:54:45 24 4
gpt4 key购买 nike

我尝试更改 Android 操作栏上 homeAsUp 按钮的颜色,但没有成功。我需要在运行时执行此操作。这是我得到的:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_register_one, menu);

MenuItem homeItem = null;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
homeItem = menu.findItem(R.id.home);
} else {
homeItem = menu.findItem(R.id.up);
}

if (homeItem == null) {
// I always wind up with a null homeItem
Log.e(Constants.TAG, "null");
} else {
Drawable homeIcon = (Drawable) homeItem.getIcon();
homeIcon.mutate().setColorFilter(Color.parseColor(sharedVisualElements.primaryFontColorHexString()), PorterDuff.Mode.SRC_IN);
homeItem.setIcon(homeIcon);
}

// this part works just fine
MenuItem nextItem = menu.findItem(R.id.next);
Drawable newIcon = (Drawable)nextItem.getIcon();
newIcon.mutate().setColorFilter(Color.parseColor(sharedVisualElements.primaryFontColorHexString()), PorterDuff.Mode.SRC_IN);
nextItem.setIcon(newIcon);

return true;
}

这总是以空状态的 homeItem 结束。我的操作栏看起来像这样(两个箭头应该是绿色的并且大小相同):

enter image description here

最佳答案

尝试将R.id.home更改为android.R.id.home

关于android - 尝试更改 ActionBar homeAsUp 按钮的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32426495/

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