Dialog with transparent background in Android

前端 未结 20 2431
孤城傲影
孤城傲影 2020-11-22 15:02

How do I remove the black background from a dialog box in Android. The pic shows the problem.

\"enter

相关标签:
20条回答
  • 2020-11-22 15:36
    Window window = d.getWindow();
    window.setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
    

    this is my way, you can try!

    0 讨论(0)
  • 2020-11-22 15:38
    <style name="NewDialog">
        <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:windowSoftInputMode">stateUnspecified|adjustPan</item>
        <item name="android:backgroundDimEnabled">false</item>
        <item name="android:background">@android:color/transparent</item>
    </style>
    

    use in java

    Dialog dialog = new Dialog(this, R.style.NewDialog);
    

    I hope help you !

    0 讨论(0)
  • 2020-11-22 15:38

    Dialog pop up fill default black background color or theme color so you need to set TRANSPARENT background into Dialog. Try below 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.splash);
    dialog.show();
    
    0 讨论(0)
  • 2020-11-22 15:39

    In my case solution works like this:

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

    And Additionally in Xml of custom dialog:

    android:alpha="0.8"
    
    0 讨论(0)
  • 2020-11-22 15:41

    Try this in your code:

    getWindow().setBackgroundDrawableResource(android.R.color.transparent);
    

    it will definately working...in my case...! my frend

    0 讨论(0)
  • 2020-11-22 15:41

    For anyone using a custom dialog with a custom class you need to change the transparency in the class add this line in the onCreate():

    getWindow().setBackgroundDrawableResource(android.R.color.transparent);
    
    0 讨论(0)
提交回复
热议问题