prostock
prostock

Reputation: 9545

Remove shadow in Android PopupWindow

I have created my PopupWindow using a simple LinearLayout with a background color. There is a shadow on the PopupWindow. How do I remove the shadow automatically generated for the PopupWindow. I created a PopupWindow with the following:

    View view = LayoutInflater.from(getBaseContext()).inflate(R.layout.mylayout,null);
    pop = new PopupWindow(this);
    pop.setTouchable(false);
    pop.setHeight(200);
    pop.setWidth(200);
    pop.setContentView(view);
    pop.showAtLocation(parentview, 0, 50, 50);     

Screenshot:

popup shadow

Upvotes: 6

Views: 7257

Answers (2)

Dake
Dake

Reputation: 21

You can style PopupWindows in your application. This code simply removes native shadows from all your PopupWindows

<style name="Base.AppTheme" parent="Theme.AppCompat.Light">
    <item name="android:popupMenuStyle">@style/PopupMenu</item>
</style>

<style name="PopupMenu" parent="android:Widget.Material.PopupMenu">
    <item name="android:popupElevation">0dp</item>
</style>

Upvotes: 2

Jan
Jan

Reputation: 2522

Is it possible that you are missing some code there? I'm not seeing that you are adding the pop to the view.

Anyway, to remove the shadow you have to use this line of code in the PopupWindow:

this.getWindow().setBackgroundDrawable(new ColorDrawable(0));

At least that's what worked for me...

Cheers!

Upvotes: 12

Related Questions