只允许数字作为Android Material Textfield的输入



是否有一种方法可以只接受材料文本字段中的数字,就像EditText一样,其中inputType可以指定为数字?

android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:id="@+id/textInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:hint="Seconds"
app:helperText="Enter numbers only"
app:endIconMode="clear_text"
app:startIconDrawable="@drawable/ic_timer"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/etTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"  />
</com.google.android.material.textfield.TextInputLayout>

可以在TextInputEditText标签内设置inputType

最新更新