简体   繁体   中英

Popup menu appears blank on screen

I am using a popup menu in my android application whenever the button is clicked the popup menu appears blank I have inflated a menu layout file with the popup menu. The actions are triggered but the popup menu appears to be blank. here's the screenshot of popup menu.

My adapter code:

 holder.more.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PopupMenu popupMenu = new PopupMenu(context, v);
                popupMenu.inflate(R.menu.expense_history_menu);
                popupMenu.show();
                popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        switch (item.getItemId()) {
                            case R.id.Edit:
                                Toast.makeText(context, "Edit clicked", Toast.LENGTH_SHORT).show();
                                return true;
                            case R.id.Delete:
                                spent_by.remove(position);
                                category.remove(position);
                                desc.remove(position);
                                date.remove(position);
                                share_by.remove(position);
                                notifyItemRemoved(position);
                                helper.delete_spent_history(s_id.get(position));
                                tot_amt = helper.get_trip_total_amt(t_id);
                                helper.update_total_amt(t_id, tot_amt);
                                update_due_amt();
                                return true;
                            default:
                                return false;
                        }

                    }
                });
            }
        });

My expense_history_menu layout file

    <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:id="@+id/Edit"
        android:title="Edit"/>

    <item
        android:id="@+id/Delete"
        android:title="Delete"/>

</menu>

Help me to solve this problem. Thanks in advance!

Paste this in style.xml and make changes as required.

<style name="PopupMenu" parent="AppTheme">
    <item name="android:popupBackground">@color/colorPrimary</item>
    <item name="android:textColor">@color/colorAccent</item>
</style>

Don't forget to add style="@style/PopupMenu" in expense_history_menu

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM