0

Is there a way to accept only numbers in material textfield, just like EditText where inputType can be specified as numbers?

 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>
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Eric Low
  • 11
  • 4

1 Answers1

5

You can set inputType inside TextInputEditText tag.

Abdullah Z Khan
  • 1,272
  • 1
  • 8
  • 18