In Android development, using EditText is very common. However, sometimes EditText automatically grabs focus when entering a page, causing the soft keyboard to pop up immediately. While this is convenient in some cases, most of the time we prefer the keyboard to appear only when the user explicitly clicks on the EditText.
Here is a simple and practical trick. You just need to add the following two attributes to the parent Layout of the EditText:
1 | android:focusable="true" |
The principle behind this is simple: when the user enters the page, the parent control captures the focus first. As a result, the EditText does not get focus, and the soft keyboard does not pop up automatically. The keyboard will only appear when the user clicks on the EditText.
About Me && Blog
Below is my personal intro and related links. I look forward to exchanging ideas with fellow professionals. “When three walk together, one can always be my teacher!”
- Blogger Intro
- Blog Content Navigation: A guide for my blog content.
- Curated Excellent Blog Articles - Android Performance Optimization Must-Knows
- Android Performance Optimization Knowledge Planet
One walks faster alone, but a group walks further together.
