Home > Enterprise >  How to change the default background color of AlertDialog from translucent to transparent
How to change the default background color of AlertDialog from translucent to transparent

Time:12-02

Want to do

I want to change the default background color of AlertDialog from translucent to transparent.

I don't want to change the color of white place.

AlertDialog image

What I tried

Added style to AlertDialog.Builder. However, this code changed the background not only translucent but also white place.

styles.xml

<style name="TransparentDialogTheme" parent="@android:style/Theme.Light">
    <item name="android:windowNoTitle">false</item>
    <item name="android:windowBackground">@android:color/transparent</item>
</style>

MainActivity.cs

var layout = LayoutInflater.Inflate(Resource.Layout.dialog_eventLogOptionMenu, null);
var dlg = new AndroidX.AppCompat.App.AlertDialog.Builder(this, Resource.Style.TransparentDialogTheme).Create();

CodePudding user response:

You can try this to add this code <item name="android:backgroundDimEnabled">false</item> to your style. It can remove the dark in the alertdialog background.

<style name="TransparentDialogTheme" parent="@android:style/Theme.Light">
    <item name="android:windowNoTitle">false</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:backgroundDimEnabled">false</item>
</style>
  • Related