Showing posts with label textview. Show all posts
Showing posts with label textview. Show all posts

Monday, May 11, 2015

Non-breaking space

You just finished implementing the UI and sent the screenshot to your designer for review. This is the feedback: "Can we make sure we don't have a dangling last word? Like what I photoshopped in the second box?"

You scratched your head and thought, how do I do that? And then you remember your best friend from HTML:  . Futhermore, you remember a post from a while ago:

  stands for non-breaking space, and you can insert that into your Android XML by \u00A0 or  . I prefer   because Android Studio highlights it with blue:

This way Android will make sure the last two words are always on the same line.

Source code

https://github.com/chiuki/advanced-textview under NonBreakingSpaceActivity.

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?