0

I have generated a popUp Menu on button click (as the layout is custom layout so couldn't use onCreateOptionsMenu). Everything is working fine except that the menu looks odd. It has got a shadow behind it which doesn't seem to go well with the app. Is there any way in which I can remove the shadow or make the popup menu look like the menu generated using onCreateOptionsMenu.

Below is the image of my popup Menu enter image description here

Code: (options_menu.xml)

<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/option1" android:title="@string/option1"
    android:orderInCategory="101" android:showAsAction="always|withText" />
<item android:id="@+id/option2" android:title="@string/option2"
    android:orderInCategory="102" android:showAsAction="always|withText" />
</menu>

Activity:

popMenuBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Context wrapper = new ContextThemeWrapper(MenuActivity.this, myPopupMenuTextAppearance);
                mPopupMenu = new PopupMenu(wrapper, v);
                MenuInflater menuInflater = mPopupMenu.getMenuInflater();
                menuInflater.inflate(R.menu.options_menu, mPopupMenu.getMenu());
                mPopupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                    public boolean onMenuItemClick(MenuItem item) {
                        switch (item.getItemId()) {
                            case R.id.option1:
                                startActivity(new Intent(this, XYZ.class));
                                return true;
                            case R.id.option2:
                                someFunction();
                                return true;
                            default:
                                Toast.makeText(this,"You Clicked : " + item.getTitle(),Toast.LENGTH_SHORT).show();
                                return true;
                        }
                    }
                });
                mPopupMenu.show();
            }
        });
ASN
  • 1,655
  • 4
  • 24
  • 52
  • paste the full code of menu xml file. Did you use `setBackgroundDrawable` for the shadow? Also what is the API level? – Riad Aug 17 '16 at 06:44
  • that is the entire code I have used in the menu XML file. Didn't add anything like setBackgroundDrawable. – ASN Aug 17 '16 at 06:48
  • try: `this.getWindow().setBackgroundDrawable(new ColorDrawable(0));` – Riad Aug 17 '16 at 06:49
  • should I add this code after inflating? I think I tried this already and it was throwing error near `this.getWindow()` and also `new ColorDrawable(0)` – ASN Aug 17 '16 at 06:54
  • have a look: http://stackoverflow.com/questions/21231404/how-to-change-background-color-popup-menu-android – Riad Aug 17 '16 at 07:10

0 Answers0