我为图像按钮实现了弹出菜单。弹出背景是蓝色的。我想把它改成灰色。请帮帮我。
我的代码:
btn_a.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu a_popup = new PopupMenu(getActivity().getApplicationContext(), a_period);
a_popup.getMenuInflater().inflate(R.menu.popup_a, a_popup.getMenu());
a_popup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Toast.makeText(getActivity().getApplicationContext(), "Clicked "+item.getTitle(), Toast.LENGTH_SHORT).show();
return true;
}
});
a_popup.show();
}
});
答案 0 :(得分:1)
您可以像这样使用Style,并在您的活动或整个应用程序中使用“MyTheme”样式。
<style name="MyTheme" parent="android:Theme.Light">
<item name="android:popupMenuStyle">@style/PopupMenu</item>
</style>
<style name="popMenu" parent="@android:style/Widget.PopupMenu">
<item name="android:popupBackground">@android:color/white</item>
</style>