如何更改出現在底部的菜單項的背景,點擊更改底部菜單項的背景
我使用ActionBarSherlock和頂部動作條有一個設備菜單按鈕後,藍色背景。以爲這將是底部菜單的背景。但它的白色。看起來像默認。所以,該圖標在白色背景上看起來不太好。我如何將其更改爲藍色。
我嘗試這樣:
<item name="android:panelBackground">@drawable/blue</item>
但沒有奏效。
謝謝。
如何更改出現在底部的菜單項的背景,點擊更改底部菜單項的背景
我使用ActionBarSherlock和頂部動作條有一個設備菜單按鈕後,藍色背景。以爲這將是底部菜單的背景。但它的白色。看起來像默認。所以,該圖標在白色背景上看起來不太好。我如何將其更改爲藍色。
我嘗試這樣:
<item name="android:panelBackground">@drawable/blue</item>
但沒有奏效。
謝謝。
我有類似的要求,我發現這個工作解決方案。使用以下
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
addOptionsMenuHackerInflaterFactory();
return true;
}
@SuppressWarnings("rawtypes")
static Class IconMenuItemView_class = null;
@SuppressWarnings("rawtypes")
static Constructor IconMenuItemView_constructor = null;
// standard signature of constructor expected by inflater of all View classes
@SuppressWarnings("rawtypes")
private static final Class[] standard_inflater_constructor_signature =
new Class[] { Context.class, AttributeSet.class };
protected void addOptionsMenuHackerInflaterFactory()
{
final LayoutInflater infl = getLayoutInflater();
infl.setFactory(new Factory()
{
public View onCreateView(final String name,
final Context context,
final AttributeSet attrs)
{
if (!name.equalsIgnoreCase("com.android.internal.view.menu.IconMenuItemView"))
return null; // use normal inflater
View view = null;
if (IconMenuItemView_class == null)
{
try
{
IconMenuItemView_class = getClassLoader().loadClass(name);
}
catch (ClassNotFoundException e)
{
// this OS does not have IconMenuItemView - fail gracefully
return null; // hack failed: use normal inflater
}
}
if (IconMenuItemView_class == null)
return null; // hack failed: use normal inflater
if (IconMenuItemView_constructor == null)
{
try
{
IconMenuItemView_constructor =
IconMenuItemView_class.getConstructor(standard_inflater_constructor_signature);
}
catch (SecurityException e)
{
return null; // hack failed: use normal inflater
}
catch (NoSuchMethodException e)
{
return null; // hack failed: use normal inflater
}
}
if (IconMenuItemView_constructor == null)
return null; // hack failed: use normal inflater
try
{
Object[] args = new Object[] { context, attrs };
view = (View)(IconMenuItemView_constructor.newInstance(args));
}
catch (IllegalArgumentException e)
{
return null; // hack failed: use normal inflater
}
catch (InstantiationException e)
{
return null; // hack failed: use normal inflater
}
catch (IllegalAccessException e)
{
return null; // hack failed: use normal inflater
}
catch (InvocationTargetException e)
{
return null; // hack failed: use normal inflater
}
if (null == view) // in theory handled above, but be safe...
return null; // hack failed: use normal inflater
// apply our own View settings after we get back to runloop
// - android will overwrite almost any setting we make now
final View v = view;
new Handler().post(new Runnable()
{
public void run()
{
v.setBackgroundDrawable(getResources().getDrawable(R.drawable.menubuttonselector));
// here use your own selector drawable
try
{
// in Android <= 3.2, IconMenuItemView implemented with TextView
// guard against possible future change in implementation
TextView tv = (TextView)v;
tv.setTextColor(Color.WHITE);
}
catch (ClassCastException e)
{
// hack failed: do not set TextView attributes
}
}
});
return view;
}
});
}
注意:
這是一個黑客的解決方案。當我需要它時,我無法給予足夠的時間來查找是否有任何副作用。但它完美地服務了我。希望它會對你有所幫助
什麼是IconMenuItemView_constructor? standard_inflater_constructor_signature來自哪裏? – 2015-09-02 09:11:05
你想改變你的應用程序菜單項的背景>?或整個系統?只有改變你的應用程序才行? – stinepike 2013-03-14 05:55:03
是的,只爲我的應用程序。 [ABS主題生成器](http://jgilfelt.github.com/android-actionbarstylegenerator/#name=example&compat=sherlock&theme=light_dark&actionbarstyle=solid&backColor=f44%2C100&secondaryColor=555555%2C100&tertiaryColor=3F3F3F%2C100&accentColor=33B5E5%2C100&cabBackColor=002E3E%2C100&cabHighlightColor = 33B5E5%2C100):這裏相同的顏色用於頂部和底部的操作欄。底部的操作欄是否與我通過點擊設備菜單按鈕獲得的菜單項有所不同? – 2013-03-14 06:03:44