18

I want to remove a transparent dark backgrond outside of dialog box.

enter image description here

I tried with:

final Dialog dialog = new Dialog(this);
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.WHITE));
        this.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.WHITE));
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.spinner_layout);
         getWindow().getDecorView().setBackgroundResource(android.R.color.transparent);
Madhav Bhattarai
  • 847
  • 2
  • 10
  • 29

5 Answers5

36

In addition to chuky's answer;

If your minSdkVersion value is greater than or equal to 14, you can use setDimAmount() method.

dialog.getWindow().setDimAmount(float amount);

According to reference;

amount The new dim amount, from 0 for no dim to 1 for full dim.

or

As stated previously, you can clear window flag.

Community
  • 1
  • 1
bsentuna
  • 381
  • 3
  • 4
22

Your question has already been answered here

Code from the link:

Add this to your styles.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <style name="Theme.DoNotDim" parent="android:Theme">
    <item name="android:backgroundDimEnabled">false</item>
  </style>
</resources>

And then apply the theme to your activity:

<activity android:name=".SampleActivity" android:theme="@style/Theme.DoNotDim">
Community
  • 1
  • 1
chuky
  • 1,037
  • 1
  • 12
  • 21
19

Hope this will help you...

dialog.getWindow().getDecorView().setBackgroundResource(android.R.color.transparent);
dialog.getWindow().setDimAmount(0.0f);
dialog.show();
Mahendran Candy
  • 1,114
  • 17
  • 17
0

This didn't work for me

<item name="android:backgroundDimEnabled">false</item>

i used background dim amount instead of background dim enabled

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <style name="Theme.DoNotDim" parent="android:Theme">
    <item name="android:backgroundDimAmount">0</item>
  </style>
</resources>
Thusitha Wickramasinghe
  • 1,063
  • 2
  • 15
  • 30
0

Using dialog.getWindow().setDimAmount(float amount); caused my statusbar icons to disappear.

Clearing the FLAG_DIM_BEHIND flag from window worked for me.

dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
Alif Hasnain
  • 1,176
  • 1
  • 11
  • 24