2

I created a PopupWindow like this :

PopupWindow popupWindow = new PopupWindow(LayoutInflater.from(this).inflate(R.layout.main_popup_navigation, null, false), ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
popupWindow.setWidth((int) this.getResources().getDimension(R.dimen.navigation_popup_width));
popupWindow.showAsDropDown(toolbar);

It works fine, except that it doesn't have any background. The popup's background is totally transparent.

How can I set a background (window + shadow) similar to a PopupMenu or a Spinner of the ThemeOverlay.AppCompat.Light theme? Thank You.

Greelings
  • 4,964
  • 7
  • 34
  • 70

1 Answers1

1

MainActivity.java

popupWindow.setBackgroundDrawable(this.getDrawable(R.drawable.main_bg_navigation));
popupWindow.setElevation(43);

main_bg_navigation.xml

<?xml version="1.0" encoding="utf-8"?>

<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <solid android:color="@color/white"/>

    <corners android:radius="2dp"/>

</shape>

It did the trick. :)

Edit : The white color value is "fffafafa"

Greelings
  • 4,964
  • 7
  • 34
  • 70