0

I am trying to disable comma character in the TextInputEditText. I added two parameters to my XML file(digits and input type). But I'm still able to input commas from a keyboard.

<com.google.android.material.textfield.TextInputLayout
            android:id="@+id/price"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/_10sdp"
            android:layout_marginStart="@dimen/_20sdp"
            android:layout_marginEnd="@dimen/_20sdp"
            app:counterEnabled="true"
            app:counterMaxLength="7"
            app:errorEnabled="true"
            app:hintTextColor="@android:color/holo_orange_dark"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/section_text">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/price_value"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="number"
                android:digits="0123456789."
                android:hint="@string/price_hint"
                android:maxLength="7"
                android:singleLine="true" />

        </com.google.android.material.textfield.TextInputLayout>
RaBaKa 78
  • 1,115
  • 7
  • 11
Kurik9797
  • 37
  • 3
  • 3
    Its can help you: https://stackoverflow.com/questions/21828323/how-can-restrict-my-edittext-input-to-some-special-character-like-backslash-t – sm Coder Jan 16 '22 at 14:25

1 Answers1

0

This code will help you

    price_value.setKeyListener(DigitsKeyListener.getInstance("0123456789."));
    price_value.setRawInputType(InputType.TYPE_CLASS_NUMBER);
    price_value.setFilters(new InputFilter[] { new InputFilter.LengthFilter(7) });