我創建了一個簡單的菜單,其中有兩個選項,「添加新聯繫人」&「設置」與白色PNG圖像。安卓選項菜單問題在不同版本
所以,現在,如果我在2.3.3 Android操作系統版本上運行,它看起來像下面的圖片:
:
所以,現在我能做些什麼,如果我想使背景黑色的Android 2.2,這樣我可以得到圖標可見。 請給我任何關於這個問題的建議。
我創建了一個簡單的菜單,其中有兩個選項,「添加新聯繫人」&「設置」與白色PNG圖像。安卓選項菜單問題在不同版本
所以,現在,如果我在2.3.3 Android操作系統版本上運行,它看起來像下面的圖片:
:
所以,現在我能做些什麼,如果我想使背景黑色的Android 2.2,這樣我可以得到圖標可見。 請給我任何關於這個問題的建議。
處理選項菜單的最佳方法是自定義它。
您可以自定義選項菜單,其中包括:
添加自定義字體
更改字體大小
更改字體顏色
設置背景的繪製資源(例如圖像,邊界,漸變)
要將背景改變爲邊框或漸變,您必須在res中創建資源文件夾,稱爲繪製能夠在內部創建邊界XML或漸變XML。
這都可以通過程序來完成,如下圖所示:
public class CustomMenu extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); }
public boolean onCreateOptionsMenu(android.view.Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.cool_menu, menu);
getLayoutInflater().setFactory(new Factory() {
public View onCreateView(String name, Context context,
AttributeSet attrs) {
if (name.equalsIgnoreCase( "com.android.internal.view.menu.IconMenuItemView")) {
try {
LayoutInflater li = LayoutInflater.from(context);
final View view = li.createView(name, null, attrs);
new Handler().post(new Runnable() {
public void run() {
// set the background drawable if you want that or keep it default
//either FOR image, border, gradient, drawable,etc.//
view.setBackgroundResource(R.drawable.myimage);
((TextView) view).setTextSize(20);
// set the text font and color
Typeface face = Typeface.createFromAsset(
getAssets(),"OldeEnglish.ttf");
((TextView) view).setTypeface(face);
((TextView) view).setTextColor(Color.RED); } });
return view; }
catch (InflateException e) {
//Handle any inflation exception here
} catch (ClassNotFoundException e) {
//Handle any ClassNotFoundException here
} }
return null; } });
return super.onCreateOptionsMenu(menu); }
您可以自定義選項菜單選項卡,並提供自己的背景顏色/圖片。 – Nishant
那我該如何設置菜單的背景? –
看看這個http://stackoverflow.com/questions/2944244/change-the-background-color-of-the-options-menu – Nishant