Here is the custom layout password_alert.xml
I have tried increasing the padding in ConstraintLayout
. But it still did not work.
<?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"
android:padding="15dp">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/til_password"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:hint="@string/enter_password"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:passwordToggleEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/et_enter_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Below is the code for alert dialog
val enterPassDialog = AlertDialog.Builder(this)
enterPassDialog.setTitle("Password Protected")
val pass = layoutInflater.inflate(R.layout.enter_password_dialog,null)
val etPassword = pass.findViewById<EditText>(R.id.et_enter_password)
enterPassDialog.setView(pass)
enterPassDialog.setNegativeButton("CANCEL") { dialog, _ ->
dialog.cancel()
finish()
}
enterPassDialog.setPositiveButton("OK") { _, _ ->
}
enterPassDialog.setOnCancelListener { dialog ->
}
val enterDialog = enterPassDialog.create()
enterDialog.show()
I am using Android API 22 as a test device. Here is the output image -