Android Alert Dialog with extra background

前端 未结 5 1321
半阙折子戏
半阙折子戏 2020-12-20 18:11

I recently migrated my app to Material Design and I stumbled upon this problem with my Alert Dialogs:

\"dialog

相关标签:
5条回答
  • 2020-12-20 18:50

    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;

    0 讨论(0)
  • 2020-12-20 19:07

    Use the theme in parent

    AlertDialog.THEME_DEVICE_DEFAULT_LIGHT
    
    0 讨论(0)
  • 2020-12-20 19:09

    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.

    0 讨论(0)
  • 2020-12-20 19:13

    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>
    
    0 讨论(0)
  • 2020-12-20 19:13

    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);
    
    0 讨论(0)
提交回复
热议问题