Keyboard changes for Android


#1

I want to have a TextField in a form which should only allow positive numbers and no decimals. I tried different keyboard (number,phone) types but there is none that supports my need. Is it possible to customize the same in nativescript?


#2

You can use any input format listed in official android docs.

Try,

yourTextField._setInputType(2);

make sure you run this code only for Android.


#4

This allows entering decimal values as well. I just want to enter whole numbers


#5

I think Android doesn’t have a built-in keyboard that prevents decimal. But setting a key listener seems to prevent dots.

yourTextField.nativeView.setKeyListener(android.text.method.DigitsKeyListener.getInstance("0123456789"));

This will still show the dot in keyboard, but will be ignored even if user hits it.


#6

Sorry. It was my mistake since i was getting exception in AfterViewInit method.


#7

Cool, ._setInputType(2) also prevents dot from being entered, but it still appears on keyboard.


#8

Thanks. I was otherwise planning to do validation using directive. You saved my time :slight_smile: