Text Gets Cut Off in Android DialogFragment

Viewed 138

The bottom half of the text contained in my DialogFragment is getting cut off. This is what it looks like:

enter image description here

Does anyone know what I am doing wrong, and how to fix it? Below is my current setup:

MainFragment.kt

class MainFragment(private val screenField: String): DialogFragment() {

    private lateinit var mBinding: FragmentMainBinding

    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        mBinding = FragmentMainBinding.inflate(LayoutInflater.from(context))
        mBinding.screenField.text = screenField
  
        return AlertDialog.Builder(context!!)
            .setView(mBinding.root)
            .setPositiveButton(R.string.ok, null)
            .create()
    }

    override fun onStart() {
        super.onStart()
        val width = resources.getDimensionPixelSize(400dp)
        val height = resources.getDimensionPixelSize(150dp)
        dialog?.window?.setLayout(width, height)
    }

}

fragment_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal">

    <TextView
        android:id="@+id/screen_field"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="40sp"
        android:textColor="@android:color/black"/>

</LinearLayout>
0 Answers
Related