如何在Android4.2中更改ActionBar的背景色选项菜单?我想更改Android4.2中选项(溢出)菜单的背景色。我已经尝试了所有的方法,但它仍然显示默认的颜色设置的主题。我使用了以下代码&XML吐露。MainActivity.javapublic 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>在上面的图片中,我要将菜单背景从黑色更改为动作栏中的蓝色。..我怎么能做到这一点,我做错了什么?
3 回答
MMTTMM
TA贡献1869条经验 获得超4个赞
<resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light"> <!-- This is the styling for action bar --> <item name="actionBarStyle">@style/MyActionBar</item> <!--To change the text styling of options menu items</item>--> <item name="android:itemTextAppearance">@style/MyActionBar.MenuTextStyle</item> <!--To change the background of options menu--> <item name="android:itemBackground">@color/skyBlue</item> </style> <style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse"> <item name="background">@color/red</item> <item name="titleTextStyle">@style/MyActionBarTitle</item> </style> <style name="MyActionBarTitle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"> <item name="android:textColor">@color/white</item> </style> <style name="MyActionBar.MenuTextStyle" parent="style/TextAppearance.AppCompat.Widget.ActionBar.Title"> <item name="android:textColor">@color/red</item> <item name="android:textStyle">bold</item> <item name="android:textSize">25sp</item> </style></resources>
- 3 回答
- 0 关注
- 625 浏览
添加回答
举报
0/150
提交
取消