Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 667
prostock Avatar asked Dec 19 '12 20:12

prostock


2 Answers

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!

like image 65
Jan Avatar answered Nov 15 '22 07:11

Jan


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>
like image 22
Dake Avatar answered Nov 15 '22 07:11

Dake