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);
So, create a new XML file under res->drawable directory. Above code will generate custom dialog with fully transparent background. The parent element of this file is RelativeLayout. I have set the background color of this relativelayout as the fully transparent with opacity 67.
You can actually apply a hex code color that is transparent. The hex code for transparent white (not that the color matters when it is fully transparent) is two zeros followed by white's hex code of FFFFFF or 00FFFFFF.
Add this code
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
Or this one instead:
dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
TL;DR; You just need two things, firstly in your style
do something like:
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
Secondly, make 100% sure said style
gets applied to your dialog (maybe by passing to constructor).
<style name="NewDialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowTitleStyle">@null</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:background">@android:color/transparent</item>
</style>
Use in Java:
Dialog dialog = new Dialog(this, R.style.NewDialog);
I hope helps you !
I've faced the simpler problem and the solution i came up with was applying a transparent bachground THEME. Write these lines in your styles
<item name="android:windowBackground">@drawable/blue_searchbuttonpopupbackground</item>
</style>
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
And then add
android:theme="@style/Theme.Transparent"
in your main manifest file , inside the block of the dialog activity.
Plus in your dialog activity XML set
android:background= "#00000000"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With