0

I'm trying to remove or change the color or background when this dialog appear:

enter image description here

is it possible to do it from the dialog?

Dialog function:

fun showAddNoteDialog() {
    val dialog = Dialog(requireActivity())
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
    dialog.setCancelable(true)

    dialog.setContentView(R.layout.ilmnotes_dialog)
    btn_add = dialog.findViewById(R.id.btn_add)
    titleEditText = dialog.findViewById(R.id.title)
    noteDescText = dialog.findViewById(R.id.noteDesc)
    date_container = dialog.findViewById(R.id.date_container)
    date_container.applyClickShrink()


    date_container.setOnClickListener {
        val datePicker: DialogFragment = DatePickerFragment()
        // Get Current Date
        val c = Calendar.getInstance()
        mYear = c[Calendar.YEAR]
        mMonth = c[Calendar.MONTH]
        mDay = c[Calendar.DAY_OF_MONTH]

        val datePickerDialog = DatePickerDialog(
            it.context,
            DatePickerDialog.OnDateSetListener { view, year, monthOfYear, dayOfMonth ->
                Toast.makeText(
                    it.context,
                    "$year-$monthOfYear-$dayOfMonth",
                    Toast.LENGTH_LONG
                ).show()

            }, mYear, mMonth, mDay
        )
        datePickerDialog.show()
    }


    btn_add.setOnClickListener {
        postNote(dialog)
    }



    dialog.show()

}

so I'm trying to hide the page behind the dialog not the dialog background itself

what is the correct way to achieve this?

Enigma
  • 353
  • 4
  • 14
  • 1
    Give your some opacity(alpha) to parent layout when open the dialog or apply dim effect in your dialog. – Piyush Aug 20 '21 at 06:56
  • is it possible to guide me step by step because I'm new to Kotlin – Enigma Aug 20 '21 at 06:57
  • `yourLayout.alpha=0.5F` or `yourLayout.setBackgroundColor(Color.parseColor("#efefef"))` add this line after `datePickerDialog.show()` – Sniffer Aug 20 '21 at 07:24
  • Might want to check this older post: https://stackoverflow.com/questions/15007272/how-to-change-the-background-color-around-a-dialogfragment/20286069#20286069 – Javatar Aug 20 '21 at 07:50

2 Answers2

1

Create a layout with full screen

ilmnotes_dialog.xml

<?xml version="1.0" encoding="utf-8"?>
<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="match_parent"
    android:layout_height="match_parent">

    //Container here 

</androidx.constraintlayout.widget.ConstraintLayout>

Kotlin code

val dialog = Dialog(this, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen)

dialog.setContentView(R.layout.ilmnotes_dialog)
val window = dialog.window
window!!.setBackgroundDrawableResource(R.color.dialog_color)
dialog.show()

create a color variable in color.xml

<color name="dialog_color">#80BB86FC</color>

Note: here BB86FC is the color, so change as per your UI and 80 is the alpha, FF is complete opaque and 00 is transparent

Kunu
  • 5,078
  • 6
  • 33
  • 61
0

Checkout this older post: How to change the background color around a DialogFragment?

(considdering using a DialogFragment)

Javatar
  • 2,518
  • 1
  • 31
  • 43