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