Custom PopupMenu (layout)

A PopupMenu is meant for displaying Menus and there really isn’t a good way of customizing the appearance of the menu items. If you want something more flexible, your answer is ListPopupWindow. private static final String TITLE = “title”; private static final String ICON = “icon”; private List<HashMap<String, Object>> data = new ArrayList<HashMap<String, Object>>(); // … Read more

android popup menu text color (AppCompat)

In styles.xml <style name=”itemTextStyle.AppTheme” parent=”@android:style/TextAppearance.Widget.IconMenu.Item”> <item name=”android:textColor”>@drawable/color_item_popup</item> <item name=”android:textSize”>@dimen/text_content</item> </style> and add in AppTheme <item name=”android:itemTextAppearance”>@style/itemTextStyle.AppTheme</item> color_item_popup.xml <selector xmlns:android=”http://schemas.android.com/apk/res/android”> <item android:state_pressed=”true” android:color=”@color/primary_text”/> <item android:state_focused=”true” android:color=”@color/primary_text”/> <item android:color=”@color/secondary_text”/> </selector>

Android custom dropdown/popup menu

Update: To create a popup menu in android with Kotlin refer my answer here. To create a popup menu in android with Java: Create a layout file activity_main.xml under res/layout directory which contains only one button. Filename: activity_main.xml <RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:tools=”http://schemas.android.com/tools” android:layout_width=”match_parent” android:layout_height=”match_parent” android:paddingBottom=”@dimen/activity_vertical_margin” android:paddingLeft=”@dimen/activity_horizontal_margin” android:paddingRight=”@dimen/activity_horizontal_margin” android:paddingTop=”@dimen/activity_vertical_margin” tools:context=”.MainActivity” > <Button android:id=”@+id/button1″ android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_alignParentLeft=”true” android:layout_alignParentTop=”true” … Read more

PopupMenu with icons [duplicate]

This way works if you’re using AppCompat v7. It’s a little hacky but significantly better than using reflection and lets you still use the core Android PopupMenu: PopupMenu menu = new PopupMenu(getContext(), overflowImageView); menu.inflate(R.menu.popup); menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { … }); MenuPopupHelper menuHelper = new MenuPopupHelper(getContext(), (MenuBuilder) menu.getMenu(), overflowImageView); menuHelper.setForceShowIcon(true); menuHelper.show(); res/menu/popup.xml <?xml version=”1.0″ encoding=”utf-8″?> <menu xmlns:android=”http://schemas.android.com/apk/res/android”> … Read more