-2

How to remove black background of popups. I am using showAtLocation method to show the popup. I followed this but no use. I tried the following method:

popup.getContentView().setBackgroundResource(android.R.color.transparent);
Community
  • 1
  • 1
Prashanth Debbadwar
  • 1,047
  • 18
  • 33

2 Answers2

2

You can set background to the root element of your popup layout. To remove the default black background from the popup setBackgroundDrawable(null)

Example:

Background for popup window layout

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"

    android:background="@drawable/background_rectangle_round"
    android:backgroundTint="@color/colorPrimary">
...

In your pop up window class

...
  setBackgroundDrawable(null)
...

Syed Umair
  • 1,480
  • 1
  • 13
  • 14
0

Just set a background colour in main layout-element of your layout. Transparent is not a very useful colour for a pop-up window.

So i mean set a background in the layout file of the contentView used in: PopupWindow(View contentView, int width, int height, boolean focusable)

Erik Duisters
  • 111
  • 2
  • 4
  • It worked for me but one problem. earlier I was creating popup lik this popup = new PopupWindow(ChallengerActivity.this); at that point in time popup was closing when I click outside the popup but now It is not closing. I tried many solutions but no result. – Prashanth Debbadwar Sep 04 '15 at 13:14