0

白いpng画像で「新しい連絡先を追加」と「設定」という2つのオプションを備えた1つのシンプルなメニューを作成しました。

したがって、2.3.3 android OSバージョンで実行すると、次の画像のようになります。

Android2.3.3オプションメニュー

2.2 android osで実行すると、次の画像のようになります。

ここに画像の説明を入力してください

では、Android 2.2で背景を黒にして、アイコンを表示したい場合はどうすればよいですか。この問題に関する提案をお願いします。

4

1 に答える 1

1

オプションメニューを扱う最良の方法は、それをカスタマイズすることです。

次のようなオプションメニューをカスタマイズできます。

カスタムフォントを追加する

文字の大きさを変える

フォントの色を変更する

背景を描画可能なリソース(画像、境界線、グラデーションなど)に設定します

背景を境界線またはグラデーションに変更するには、resにdrawableというリソースフォルダーを作成し、その中に境界線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);     } 
于 2012-08-27T06:33:19.767 に答える