工具栏中的“保存”项目变灰只发生在设计模式下,但绝不会发生在运行时。
我正在使用这段代码:
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
if(count > 0) {
menuItemSave.setEnabled(true);
} else {
menuItemSave.setEnabled(false);
}
return true;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.options_menu, menu);
menuItemSave = menu.findItem(R.id.save);
return true;
}
它正在启用/禁用,但它在禁用时真的不会变成灰色。
最佳答案
当按钮启用或禁用时,您可以使用自定义颜色来更改颜色。 [ 根据您的要求更改颜色 ] 颜色/custom_button_color.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#FF0000" android:state_enabled="false" />
<item android:color="#CCCCCC"/>
</selector>
在 menu.xml 文件中设置您需要的按钮项,例如
android:textColor="@color/custom_button_color"
关于java - android - 菜单项保持白色甚至禁用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46612344/