0

I need to create a custom full-screen dialog with overlay background. Here is the image of the expected result:

Example of a result expected

I tried the below code but it does not show like the above image.

  1. My Dialog open dialog code is bellow
        lateinit var dialog: Dialog
        dialog = Dialog(this, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen)
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE) // before
        dialog.setContentView(R.layout.dialog)
        dialog.setCancelable(true)
        val lp = WindowManager.LayoutParams()
        lp.copyFrom(dialog.getWindow()?.getAttributes())
        lp.width = WindowManager.LayoutParams.MATCH_PARENT
        lp.height = WindowManager.LayoutParams.MATCH_PARENT
        dialog.getWindow()!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        val d: Drawable = ColorDrawable(Color.BLACK)
        d.setAlpha(130)
        dialog.getWindow()!!.setBackgroundDrawable(d)
        dialog.show()
        dialog.getWindow()!!.setAttributes(lp)

  1. Here is my dialogx.ml
        <?xml version="1.0" encoding="utf-8"?>
         <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#80000000"
            android:orientation="vertical">

        </LinearLayout>
  1. Here is my color code
        **fill color #000000  with alph 50%**

It shows the transparent background. How to make the dialog above image. Please help me.

Jenea Vranceanu
  • 4,530
  • 2
  • 18
  • 34
Enamul Haque
  • 4,789
  • 1
  • 37
  • 50
  • You are looking for a blur effect, not a semi-transparent black background. Probably this answer could help you: https://stackoverflow.com/a/31642143/7210237 There are a lot more other answers on this topic with different working solutions. – Jenea Vranceanu Sep 28 '20 at 08:07

1 Answers1

0

Dialog dialog=new Dialog(this,android.R.style.Theme_Black_NoTitleBar_Fullscreen); dialog.setContentView(R.layout.dialog); dialog.show();

Asad khan
  • 156
  • 7