如何在Android4.2中更改ActionBar的背景色选项菜单?
MainActivity.java
public class MainActivity extends Activity {@SuppressLint("NewApi")@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getActionBar().setIcon(R.drawable.ic_launcher); getActionBar().setTitle("Sample Menu"); 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"));}@Overridepublic boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); setMenuBackground(); return true;}protected void setMenuBackground(){ // Log.d(TAG, "Enterting setMenuBackGround"); getLayoutInflater().setFactory( new Factory() {
着色剂
<color name="menubg">#33B5E5</color>
MMTTMM