xamarin 如何将AlertDialog的默认背景色从半透明更改为透明

nnt7mjpx  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(216)

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.

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();
btqmn9zl

btqmn9zl1#

您可以尝试将此代码<item name="android:backgroundDimEnabled">false</item>添加到您的style中。它可以去除alertdialog背景中的黑色。

<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>

相关问题