Android Alert Dialog with extra background

风流意气都作罢 提交于 2019-11-29 13:41:39

The point is here:

<style name="Theme.AlertDialog" parent="Base.V14.Theme.AppCompat.Dialog">
    ...
    <item name="colorPrimary">@color/theme_primary</item>
    <item name="colorPrimaryDark">@color/theme_primary_dark</item>
    <item name="colorAccent">@color/theme_accent_dark</item>
    ...
    <item name="android:windowBackground">@android:color/transparent</item>
    ...
</style>
adiel

As ironman told me here, be sure that you import the right class.

Right : import android.support.v7.app.AlertDialog;

Wrong : import android.app.AlertDialog;

Use the theme in parent

AlertDialog.THEME_DEVICE_DEFAULT_LIGHT

Add below styles . You have to customise background also.

    <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:backgroundDimEnabled">false</item>
    <item name="android:background">@android:color/transparent</item>

Using below also works

<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:background">@android:color/transparent</item>

Also You can set in your code by using

dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

and this should be before setContentView

dialog.setContentView(R.layout.dialog);

I had the exact same symptom but for me it was actually that I had used the standard frameworks AlertDialog (and its Builder) instead of android.support.v7.app.AlertDialog, switching to use the one from the support library fixed the issue for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!