How do I remove the black background from a dialog box in Android. The pic shows the problem.
final Dialog dialog = new Dialog(Screen1.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.themechanger);
How do I remove the black background from a dialog box in Android. The pic shows the problem.
final Dialog dialog = new Dialog(Screen1.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.themechanger);
Attention :
don't use builder for change background
change to
When using Dialog.builder - Its not giving getwindow() option in it.
use this code it's works with me :
One issue I found with all the existing answers is that the margins aren't preserved. This is because they all override the
android:windowBackground
attribute, which is responsible for margins, with a solid color. However, I did some digging in the Android SDK and found the default window background drawable, and modified it a bit to allow transparent dialogs.First, copy /platforms/android-22/data/res/drawable/dialog_background_material.xml to your project. Or, just copy these lines into a new file:
Notice that
android:color
is set to?attr/colorBackground
. This is the default solid grey/white you see. To allow the color defined inandroid:background
in your custom style to be transparent and show the transparency, all we have to do is change?attr/colorBackground
to@android:color/transparent
. Now it will look like this:After that, go to your theme and add this:
Make sure to replace
newly_created_background_name
with the actual name of the drawable file you just created, and replacesome_transparent_color
with the desired transparent background.After that all we need to do is set the theme. Use this when creating the
AlertDialog.Builder
:Then just build, create, and show the dialog as usual!
In my case solution works like this:
And Additionally in Xml of custom dialog: