I am creating an AlertDialog as follows.
- I fix the dialog view to the bottom of the screen. Average width: 400, height: 200 dimensions. (Actually I want it to be something like Admob-banner)
- I always want the screen I started with show () to remain visible and the screen behind the dialog to be usable. So I made the background transparent for the user.
However, there is a problem. Dialog background cannot be clicked. How do I make the background available while the dialog remains on the screen? Also, I don't want the dialog to be closed when the user is using the background.
TestBannerDialog.kt
import android.app.AlertDialog
import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.os.CountDownTimer
import android.view.Gravity
import android.view.View
import android.view.WindowManager
class TestBannerDialog(context: Context) : Dialog(context, false, null) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.test_banner_dialog)
setCanceledOnTouchOutside(false)
window?.let {
it.attributes.gravity = Gravity.BOTTOM
it.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
}
}
}
test_banner_dialog.xml
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="24dp">
<ImageView ....... />
<TextView ....... />
</androidx.constraintlayout.widget.ConstraintLayout>