Android custom view receives input from the input method

preface

Perhaps for many newcomers, seeing this topic, they think of only EditText and textview controls that can receive input from the input method. In fact, as long as they are subclasses of view, they can receive input from the input method.

Now let's implement it step by step. The first step is to have a subclass of view.

Implementation method

I just set it casually here. The important thing is the returned inputconnect object.

Many questions arise here. For example, what should we do if we need to pop up the input method when we click View?

We can control the pop-up and retraction of the input method through the inputmethod manager.

In the non full screen state, we can monitor the bounce and retraction of the input method by changing the layout size, but in the full screen state, sorry, it is not allowed at present. For example, if the user clicks the hide button of the input method, it will only trigger the finishcomposingtext method, but it will also trigger this method at other times. Therefore, it is not feasible to monitor the retraction of the input method through this method. The inputmethodmanager does not provide relevant APIs, and has tried to obtain the information provided by the IMM

It didn't work.

In another case, the current activity exits, the input method is still alive, and there is nothing entered. Moreover, we have tried all methods of hiding input methods, and we can't hide input methods normally.

Here's a cheap method. When the input method is alive, we click the back button to actively hide the input method. Click again to distribute and pass the key events to the activity.

Therefore, we need to simulate a return event.

summary

The above is the whole content of this article. I hope the content of this article can bring some help to Android developers. If you have any questions, you can leave a message.

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