Java ActionBar菜单更改颜色错误?

Java ActionBar菜单更改颜色错误?,java,android,android-actionbar,Java,Android,Android Actionbar,我在这三行有错误 package com.cartperk.android.cartperk.ui; import android.R; import android.annotation.SuppressLint; import android.app.Activity; import android.content.res.Resources; import android.graphics.Color; import android.graphics.drawab

我在这三行有错误

package com.cartperk.android.cartperk.ui;

  import android.R;
  import android.annotation.SuppressLint;
  import android.app.Activity;
  import android.content.res.Resources;
  import android.graphics.Color;
  import android.graphics.drawable.ColorDrawable;
  import android.os.Bundle;
  import android.os.Handler;
  import android.view.InflateException;
  import android.view.LayoutInflater;
  import android.view.LayoutInflater.Factory;
  import android.view.Menu;
  import android.view.View;
  import android.widget.TextView;

  public class MenuActionBar extends Activity {

@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    getActionBar().setBackgroundDrawable(new 
               ColorDrawable(Color.parseColor("#33B5E5"))); 

    int titleId = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");
    TextView titleText = (TextView)findViewById(titleId);
    titleText.setTextColor(Color.parseColor("#ffffff"));
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // TODO Auto-generated method stub
     getMenuInflater().inflate(R.menu.main, menu);
        setMenuBackground();
        return true;
}

private void setMenuBackground() {
    // TODO Auto-generated method stub
    getLayoutInflater().setFactory( new Factory() { 

        @Override
        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.setBackgroundResource( R.color.menubg);
                            // 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;
        }});

}
 }
新工厂要求再次创建onCreateView,即使它存在 而R.menu.main表示它无法解析到main
最后一个错误上下文和属性集要求我创建它们的类。

将品牌颜色添加到操作栏的最佳方法是创建自定义样式。一个很好的工具是

getLayoutInflater().setFactory( new Factory() { 

        @Override
        public View onCreateView(String name, Context context,AttributeSet attrs)