Android click anywhere outside the EditText text text box to hide the keyboard

1. Implementation method 1:

By setting the click event for the parent layout of the current interface layout file (equivalent to setting the click event for the whole activity), the keyboard is hidden in the event

Add ID and clickable = true

Then, in oncreate, add listening for onclick events:

In onclick:

This can perfectly solve the hidden effect outside the input box. It can be used when the layout is not particularly complex or there are few other touch events.

2. Realization idea 2:

Each action via dispatchtouchevent_ In the down event, dynamically judge the click event in the area other than EditText itself, and then mask it in the event.

Isshoudhideinput (view v, motionevent E) method:

This method is troublesome to implement. The solution is similar to the event distribution mechanism in IOS. It is clear to deal with hidden events. Through layer by layer event distribution, judge whether it is in the area that needs to be shielded.

1. Implementation method 1:

By setting the click event for the parent layout of the current interface layout file (equivalent to setting the click event for the whole activity), the keyboard is hidden in the event

Add ID and clickable = true

Then, in oncreate, add listening for onclick events:

In onclick:

This method is troublesome to implement. The solution is similar to the event distribution mechanism in IOS. It is clear to deal with hidden events. Through layer by layer event distribution, judge whether it is in the area that needs to be shielded.

The above is the solution introduced by Xiaobian to hide the keyboard anywhere outside the edit text text box. I hope it will be helpful to you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

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
分享
二维码
< <上一篇
下一篇>>