Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DialogFragment rounded corners - how to set transparency

I've made custom layout for dialogFragment with rounded corners but when dialog is called corners are rounded he looks like below.

https://i.sstatic.net/rnlKJ.png

I know i need to set transparency dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent); but I dont know where to put this in my code, additionally I'm using Kotlin.

Below is the part of code where Dialog is called.

 myDialog = Event_Dialog.newInstance(args,args1)
                myDialog.show(fragmentManager, "MyDialog")

This is Event_Dialog class.

class Event_Dialog : DialogFragment() {

companion object {

    fun newInstance(bundle: String, bundle1: String): Event_Dialog {
        //description
        val args: Bundle = Bundle()
        args.putString("desc", bundle)
        //link
        args.putString("link", bundle1)

        val fragmentDialog = Event_Dialog()
        fragmentDialog.arguments = args

        return fragmentDialog
    }
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
    val x = inflater.inflate(R.layout.event_detail, container, false)
some code.......
return x

Could you tell me guys where I should set the transparency of custom background ? Thanks !

like image 834
radekdob Avatar asked Sep 03 '25 13:09

radekdob


1 Answers

just put it in oncreatedialog like :

 override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
    val dialog = super.onCreateDialog(savedInstanceState)
    dialog.window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
    return dialog
}

and i suggest that you use a framelayout as a root view for your dialog ( match parent frame ) and design your center layout in it

like image 191
Vahab Ghadiri Avatar answered Sep 05 '25 04:09

Vahab Ghadiri