我有一个使用主题Theme.Sherlock.Light.DarkActionBar的ActionBarSherlock应用程序。操作栏是深色的,我的菜单图标是浅色的。当我在小布局上运行我的应用程序时,2到3个带有图标的菜单项显示在溢出菜单中。
在Android 3+上,overflow菜单项不会显示它们的图标,但在Android 2.3和更早的版本上,我看到菜单磁贴上几乎看不见图标,因为磁贴的颜色是白色的,而图标接近白色。

如您所见,亮图标在白色背景上不可见,但它们必须具有浅色才能在深色操作栏上可见:

当菜单项显示在溢出菜单中时,我可以删除图标吗?
发布于 2013-03-09 23:35:40
我也面临着同样的问题:
有许多方法可以实现这一点,而不是删除图像:
1)您可以使用各自的可绘制文件夹来放置明暗图像。
2)您也可以通过检查您的设备版本,通过菜单的代码来更改背景色。
如果您的设备不支持溢出菜单,您可以更改菜单的背景色,也可以更改菜单文本颜色。
我也面临着同样的问题,并使用以下方法解决了这个问题:
static final Class<?>[] constructorSignature = new Class[] {Context.class, AttributeSet.class};
class MenuColorFix implements LayoutInflater.Factory {
public View onCreateView(String name, Context context, AttributeSet attrs) {
if (name.equalsIgnoreCase("com.android.internal.view.menu.ListMenuItemView")) {
try {
Class<? extends ViewGroup> clazz = context.getClassLoader().loadClass(name).asSubclass(ViewGroup.class);
Constructor<? extends ViewGroup> constructor = clazz.getConstructor(constructorSignature);
final ViewGroup view = constructor.newInstance(new Object[]{context,attrs});
new Handler().post(new Runnable() {
public void run() {
try {
view.setBackgroundColor(Color.BLACK);
List<View> children = getAllChildren(view);
for(int i = 0; i< children.size(); i++) {
View child = children.get(i);
if ( child instanceof TextView ) {
((TextView)child).setTextColor(Color.WHITE);
}
}
}
catch (Exception e) {
Log.i(TAG, "Caught Exception!",e);
}
}
});
return view;
}
catch (Exception e) {
Log.i(TAG, "Caught Exception!",e);
}
}
return null;
}
}
public List<View> getAllChildren(ViewGroup vg) {
ArrayList<View> result = new ArrayList<View>();
for ( int i = 0; i < vg.getChildCount(); i++ ) {
View child = vg.getChildAt(i);
if ( child instanceof ViewGroup) {
result.addAll(getAllChildren((ViewGroup)child));
}
else {
result.add(child);
}
}
return result;
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
LayoutInflater lInflater = getLayoutInflater();
if ( lInflater.getFactory() == null ) {
lInflater.setFactory(new MenuColorFix());
}
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.myMenu, menu);
}3)更改styles.xml文件的背景色
<style name="Theme.MyTheme" parent="Theme.Sherlock.ForceOverflow">
<item name="actionBarStyle">@style/Widget.MyTheme.ActionBar</item>
<item name="android:actionBarStyle">@style/Widget.MyTheme.ActionBar</item>
</style>
<style name="Widget.MyTheme.ActionBar" parent="Widget.Sherlock.ActionBar">
<item name="android:background">#ff000000</item>
<item name="background">#ff000000</item>
</style>对我来说,这3个都运行得很好。
希望,这也适用于你
发布于 2013-03-07 16:49:44
您可以使用配置限定符。例如:
创建一个可绘制的文件夹/res/ drawable -v11/将所有的“光”图标放入其中。
对于较暗的图标,请使用/res/drawable/文件夹。
请确保在两个文件夹中使用相同的文件名。
我希望我已经理解了你的问题,这可能会对你有所帮助。
然而,如果你想仅仅为了溢出菜单而改变绘图工具,我认为这是不可能的。这也是因为菜单图标并不是这样使用的。ActionBarSherlock可能也是因为这样的问题,而不是官方的库。
发布于 2013-05-18 13:27:37
OS2.x是一团糟,因为选项菜单的背景可能是黑色或白色,这取决于设备,无法确定是哪一个。
简单的解决办法是在Android2.x和2.x下使用灰色(#888888)图标,并将你的现代(ICS/JB)图标放在现代设备的v11文件夹中:
drawable // old school icons
drawable-v11 // modern icons当然,这意味着drawable-mdpi-v11、drawable-hdpi-v11等等。
https://stackoverflow.com/questions/15130499
复制相似问题