How do i style a PopupMenu in android? i want a grey background and a icon before the text.
like this:
<style name="GreenText" parent="@android:style/PopupMenu">
<item name="android:textColor">#00FF00</item>
</style>
or can i better build an PopupWindow like in this thread?
inflate popup menu items programatically
Thank you.
i couldn't find an easy way to style my PopupMenu so i used "PopupWindow" instead, pass a listview to it , and style it as i want.
popView=layoutInflater.inflate(R.layout.pop_layout, null); // layout with a listview to put in the popup window
lv=(ListView)popView.findViewById(R.id.pop_listview); // then set listview parameters
final PopupWindow contentsopupWindow = new PopupWindow(popView,LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
contentsopupWindow.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.pixel_dot));// set a background so the menu disappears when you click outside it
contentsopupWindow.setTouchable(true);
contentsopupWindow.setFocusable(true);
contentsopupWindow.setOutsideTouchable(true);
contentsopupWindow.setTouchInterceptor(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
contentsopupWindow.dismiss();
return true;
}
return false;
}
});
WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
contentsopupWindow.showAsDropDown(anchorView);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With