I try to create a custom DialogFragment. The problem is it does not look the way I want it to be. I created a layout:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="239dp"
android:background="#00f">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="210dp"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:background="@drawable/pop_up_shape"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</androidx.constraintlayout.widget.ConstraintLayout>
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
I created a class:
class AddPlaylistPopUp: DialogFragment(){
override fun onCreateDialog(
savedInstanceState: Bundle?
): Dialog {
val builder = AlertDialog.Builder(context!!)
builder.setView(R.layout.add_playlist_popup_layout)
return builder.create()
}
}
and I present it like this:
fun openDialog(){
val fm = fragmentManager!!
val editNameDialogFragment = AddPlaylistPopUp()
editNameDialogFragment.show(fm, "fragment_edit_name")
}
this is the result:
as you see the pop up looks not like the custom layout I created... What am I doing wrong? There are unnecessary side margins, the green view is bigger and the button is inside the green view. I tried many things but nothing worked. How do I make it look 100% like my layout?