Simple and perfect solution for Android to judge whether the soft keyboard pops up and hides (recommended)

There is an edit box in the recent project. Below is a listview. After triggering the pop-up soft keyboard of the edit box, the listview can slide, and the item of the listview can respond to clicking. The effect of this experience is very bad. So I want to judge whether the keyboard pops up when sliding or clicking item. If it pops up, hide it.

A search on the Internet found that Android does not directly provide pop-up and hidden judgment of the soft keyboard. Some solutions, such as judging the height of the parent control or judging

It didn't work, so we started with the official documents.

It is found that inputmethodmanager has a method isactive (view): if view is the active view of input method, it returns true. That is, if the view triggers the pop-up of the soft keyboard, it returns true. Wow, that's easy

Then let another view force the focus, so that isactite (editext) is false

This method is relatively simple, the code is relatively short and easy to understand. I hope it can help people in need, and it will not waste my debugging hours.

Attach Code:

PS: getactivity(), if the keyboard pops up manually Getcurrentfocus() is changed to searchedittext And the manually popped keyboard isactie () fails, which can be judged by the mark

The above is all about the simple and perfect solution (recommended) to pop up and hide the Android judgment soft keyboard brought by Xiaobian. I hope you can support more programming tips~

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>