I want to remove the black background on custom dialog as shown in the picture. I\'m sure the black background was from the dialog, not from app\'s background.
Sonehow getWindow().setBackgroundDrawable()
didn't work for me with AlertDialog
. I found an easier solution using Dialog. Here's my code -
final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.setContentView(R.layout.popup_window);
dialog.show();
Use below two code lines. Tested as well.
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
Remove the background opacity color, you just need to set the DimAmount
dialog.getWindow().setDimAmount(float amount);
The new dim amount, from 0 for no dim to 1 for full dim.
Try this:
myDialog.getWindow().clearFlags(LayoutParams.FLAG_DIM_BEHIND);
I had the same problem with my custom dialog based on the Alertdialog.Builder, which had a black background showing in the title and the body when i use:
builder.setView(rootView)
.setTitle(dialog_title)
.setMessage(dialog_mesg)
solution was 1- Use one of the pre-defines alert dialog builder's themes:
THEME_DEVICE_DEFAULT_LIGHT worked best for me
2 - set the default dialog button (positive / negative) colors to which ever color you desire like so:
Button b = mAlertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
Button d = mAlertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
b.setTextColor(ContextCompat.getColor(getActivity(), R.color.primary));
d.setTextColor(ContextCompat.getColor(getActivity(), R.color.primary));
check the below blog post for more detail and tricks to theming options: http://blog.supenta.com/2014/07/02/how-to-style-alertdialogs-like-a-pro/
tested on Oreo 8.1
After trying dozens of other solutions for this problem, what ended up working for me is:
<style name="translucentDialog" parent="android:Theme.Holo.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
</style>
And then setting my dialog to use this theme.