문제

Let's say I have an EditText and I want to restrict it to 0-9 and A-F (inclusive), for hex input. Is there a way I can do that? I tried looking at InputFilters and I'm not sure that's the right way. Has anyone achieved this?

도움이 되었습니까?

해결책

Set the input type to number and digits to "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" In an xml file it would look like this:

<EditText
    android:id="@+id/hexedit"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:digits="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    android:inputType="number"      
/>

You can experiment with different inputTypes to see which soft keyboard layout they bring up.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top