Saturday, September 5, 2009

Customize the soft keyboard

When you type something in Puzzle Pal, it is usually just a sequence of characters, not a valid word. The Android soft keyboard has auto-correct as default, which can be a bit annoying. Fortunately, you can customize the soft keyboard by specifying the input type of the TextView.

When I am expecting text, I use this:

textView.setInputType(
  InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);

Phone spell only accept digits, so I use this instead:

textView.setInputType(InputType.TYPE_CLASS_PHONE);

setInputType tells the system what you expect as your input. I picked visible password for text because that turns off auto correction. For phone spell, well, it is much more intuitive to offer a phone pad, isn't it?

No comments:

Inline coding questions will not be answered. Instead, ask on StackOverflow and put the link in the comment.

Post a Comment