简体   繁体   中英

Prevent Soft Keyboard from hiding on button click

I have an EditText with a button next to it. The button adds the keyword from the EditText to a list and clears the EditText so that the user can enter another keyword. Every time the button is pressed, the keyboard goes away. I have tried android:focusable="false" and android:focusableInTouchMode="false" on the button and I have tried editText.requestFocus() in the button on click method. The keyboard still disappears. The behavior I want can be seen in the Google Messenger app and the Out of Milk app (and probably many other todo list apps).

Can't comment yet, but I've used the first code block in an app I have for adding a filter window (consisting of an edit text, a set of toggle buttons and a set of check boxes) in a click listener and showing the keyboard. I assume it would work with the text view already visible. Just getting focus doesn't open the keyboard automatically, or else it didn't for me either.

http://developer.android.com/training/keyboard-input/visibility.html

Will add code tomorrow if still open.

I had an override dispatchTouchEvent in my activity to do the exact opposite thing. I wanted the keyboard to disappear when tapping outside of another EditText. I could share the code but I think it is arbitrary. In the end, it helped a lot to really understand touch events by reading this article .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM