я реализовал DialogFragment , но это выглядит так:
вместо этого (из предварительного просмотра XML):
фрагмент onViewCreated
val button = view.findViewById(R.id.button_register) as Button
button.setOnClickListener{
Log.d(TAG, "Clicked")
val dialog = SuccessDialog()
dialog.show(fragmentManager, "success dialog")
}
Класс SuccessDialog
class SuccessDialog: DialogFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.dialog_success, container, false)
val button: Button = view.findViewById(R.id.button_ok)
button.setOnClickListener{
dialog.dismiss()
}
return view
}
}
XML диалога:
<?xml version = "1.0" encoding = "utf-8"?>
<android.support.constraint.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:orientation = "vertical"
android:layout_width = "250dp"
android:layout_height = "200dp"
android:background = "@color/colorPrimaryDark"
android:padding = "5dp"
android:layout_gravity = "center">
<ImageView
android:id = "@+id/imageView"
android:layout_width = "47dp"
android:layout_height = "46dp"
android:layout_marginStart = "8dp"
android:layout_marginLeft = "8dp"
android:layout_marginEnd = "8dp"
android:layout_marginRight = "8dp"
app:layout_constraintEnd_toEndOf = "parent"
app:layout_constraintStart_toStartOf = "parent"
app:layout_constraintTop_toTopOf = "parent"
tools:srcCompat = "@drawable/ic_check_mark_24dp"
android:contentDescription = "@string/checkmark" />
<TextView
android:id = "@+id/textView3"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_marginStart = "8dp"
android:layout_marginLeft = "8dp"
android:layout_marginTop = "8dp"
android:layout_marginEnd = "8dp"
android:layout_marginRight = "8dp"
android:text = "@string/success"
android:textColor = "@android:color/white"
android:textSize = "18sp"
android:textStyle = "bold"
app:layout_constraintEnd_toEndOf = "parent"
app:layout_constraintStart_toStartOf = "parent"
app:layout_constraintTop_toBottomOf = "@+id/imageView" />
<TextView
android:id = "@+id/textView6"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_marginStart = "8dp"
android:layout_marginLeft = "8dp"
android:layout_marginTop = "8dp"
android:layout_marginEnd = "8dp"
android:layout_marginRight = "8dp"
android:gravity = "center"
android:text = "@string/thank_you"
android:textColor = "@android:color/white"
android:textStyle = "italic"
app:layout_constraintEnd_toEndOf = "parent"
app:layout_constraintStart_toStartOf = "parent"
app:layout_constraintTop_toBottomOf = "@+id/textView3" />
<Button
android:id = "@+id/button_ok"
android:layout_width = "86dp"
android:layout_height = "40dp"
android:layout_marginStart = "8dp"
android:layout_marginLeft = "8dp"
android:layout_marginTop = "8dp"
android:layout_marginEnd = "8dp"
android:layout_marginRight = "8dp"
android:layout_marginBottom = "8dp"
android:text = "@string/ok"
app:layout_constraintBottom_toBottomOf = "parent"
app:layout_constraintEnd_toEndOf = "parent"
app:layout_constraintStart_toStartOf = "parent"
app:layout_constraintTop_toBottomOf = "@+id/textView6" />
</android.support.constraint.ConstraintLayout>




tools:...
это просто для предварительный просмотр xml . Поэтому, пожалуйста, используйте:
app:srcCompat = "..."
вместо
tools:srcCompat = "..."
Чтобы изменить размеры, используйте это в onCreateView вашего SuccessDialog
if (getDialog() != null && getDialog().getWindow() != null) {
getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
}
что исправило изображение. мое изображение сейчас там, но в нем отсутствуют все
TextViewи кнопка, и размеры определенно не 250dp x 200dp