tenten tenten - 5 months ago 42
Android Question

Android popup with gray background

I have implemented a Popup menu for a image button. Popup background is blue. I want change it to gray. Please help me on this.

My Code :

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();
}
});

Answer

You can use Style like this and use "MyTheme" style in your activity or from the whole application.

<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>
Comments