1

そのメニューの背景色を黒、フォントの色を白にする必要があります。すべてのデバイスで同じです。別のデバイスでテストしましたが、一部のデバイスでは希望どおりに見えますが、一部のデバイスでは白いメニューと黒いフォントのように見える

それを変更して静的にすることはできますか?

4

2 に答える 2

1

ああ、あなたは次の方法でこれを行うことができます...。

以下はコードです....その背景色は黒で、フォントはandoridのすべての電話で白です

    @Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater menuInflater = getMenuInflater();
    /*
     * if (Integer.parseInt(android.os.Build.VERSION.SDK) <= 8)
     * menuInflater.inflate(R.menu.capture_black, menu); else
     */
    menuInflater.inflate(R.menu.main_capture, menu);

    setMenuBackground();
    return super.onCreateOptionsMenu(menu);
}

protected void setMenuBackground() {
    // Log.d(TAG, "Enterting setMenuBackGround");
    getLayoutInflater().setFactory(new Factory() {
        public View onCreateView(String name, Context context, AttributeSet attrs) {
            if (name.equalsIgnoreCase("com.android.internal.view.menu.IconMenuItemView")) {
                try { // Ask our inflater to create the view
                    LayoutInflater f = getLayoutInflater();
                    final View view = f.createView(name, null, attrs);
                    /*
                     * The background gets refreshed each time a new item is
                     * added the options menu. So each time Android applies
                     * the default background we need to set our own
                     * background. This is done using a thread giving the
                     * background change as runnable object
                     */
                    new Handler().post(new Runnable() {
                        public void run() {
                            // sets the background color
                            view.setBackgroundColor(Color.BLACK);
                            // sets the text color
                            ((TextView) view).setTextColor(Color.WHITE);
                            // sets the text size
                            ((TextView) view).setTextSize(18);
                        }
                    });
                    return view;
                } catch (InflateException e) {
                } catch (ClassNotFoundException e) {
                }
            }
            return null;
        }
    });
}
于 2012-10-16T11:26:57.380 に答える
0

そのためのカスタムメニューを作成する必要があります。これが優れたチュートリアルです。

http://www.codeproject.com/Articles/173121/Android-Menus-My-Way

于 2012-10-16T11:28:03.347 に答える