I need to create a custom full-screen dialog with overlay background. Here is the image of the expected result:
I tried the below code but it does not show like the above image.
- 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)
- 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>
- 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.