简体   繁体   English

如何在android中创建自定义全屏ovarlay对话框

[英]How to create custom full screen ovarlay dialog in android

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.我尝试了下面的代码,但它不像上图那样显示。

  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这是我的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.请帮我。

Dialog dialog=new Dialog(this,android.R.style.Theme_Black_NoTitleBar_Fullscreen); Dialog dialog=new Dialog(this,android.R.style.Theme_Black_NoTitleBar_Fullscreen); dialog.setContentView(R.layout.dialog); dialog.setContentView(R.layout.dialog); dialog.show();对话框显示();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM