android dialog transparent

后端 未结 6 1288
[愿得一人]
[愿得一人] 2020-11-28 09:14

I want to get rid of the border in my dialog box and make it look absolutly transparent, as if the image is on the top of screen.

相关标签:
6条回答
  • 2020-11-28 09:41

    try this:-

    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-28 09:41

    The simplest way of doing this is that in your DialogFragment's onCreate() method, call

    setStyle(DialogFragment.STYLE_NO_FRAME, 0);
    

    And if the view you returned in onCreateView does not have a background specified, the dialog's background will be just transparent.

    Why? DialogFragment.STYLE_NO_FRAME means that OS will not do any drawing in the window of the dialog, and your view is 100% responsible for drawing everything about the dialog.

    0 讨论(0)
  • 2020-11-28 09:44

    To give a translucent effect, say 50% opacity, use:

    Drawable d = new ColorDrawable(Color.BLACK);
    d.setAlpha(130);
    mDialog.getWindow().setBackgroundDrawable(d);
    

    '130' can be changed (0-255) to acheive desired opacity.

    0 讨论(0)
  • 2020-11-28 09:49

    Try below code

    Dialog mDialog = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
    
    0 讨论(0)
  • 2020-11-28 09:52

    try this:

    mDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
    
    0 讨论(0)
  • 2020-11-28 09:58

    For API 11+

    Dialog mDialog = new Dialog(mContext, android.R.style.Theme_Holo_Light_Panel);
    
    0 讨论(0)
提交回复
热议问题