0

我按照谷歌关于操作栏样式背景的教程 https://developer.android.com/training/basics/actionbar/styling.html 但是当我实现拆分操作栏时,顶部操作栏的背景发生了变化,但底部的没有。

https://dl.dropboxusercontent.com/u/37599516/Untitled.png

任何想法 ?

4

1 回答 1

0

底部显示的菜单不是操作栏,它的选项菜单。您必须为选项菜单设置样式。这可能会对您有所帮助

@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.my_menu, menu);

getLayoutInflater().setFactory(new Factory() {
@Override
public View onCreateView(String name, Context context,
AttributeSet attrs) {

if (name     .equalsIgnoreCase(“com.android.internal.view.menu.IconMenuItemView”)) {
try {
LayoutInflater f = getLayoutInflater();
final View view = f.createView(name, null, attrs);

new Handler().post(new Runnable() {
public void run() {

// set the background drawable
view     .setBackgroundResource(R.drawable.my_ac_menu_background);

// set the text color
((TextView) view).setTextColor(Color.WHITE);
}
});
return view;
} catch (InflateException e) {
} catch (ClassNotFoundException e) {
}
}
return null;
}
});
return super.onCreateOptionsMenu(menu);
}
于 2013-11-06T10:44:19.513 回答