【问题标题】:Allow only numbers as input in Android Material Textfield [duplicate]在Android Material Textfield中只允许输入数字[重复]
【发布时间】:2021-11-18 06:53:55
【问题描述】:

有没有办法只接受材料文本字段中的数字,就像可以将 inputType 指定为数字的 EditText 一样? TIA

 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>

【问题讨论】:

    标签: android


    【解决方案1】:

    您可以在TextInputEditText 标签内设置inputType

    【讨论】:

    • 感谢阿卜杜拉!它适用于 TextInputEditText
    猜你喜欢
    • 2022-12-04
    • 2016-03-28
    • 2011-11-09
    • 1970-01-01
    • 2015-08-09
    • 1970-01-01
    • 2021-01-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多