Example of display and hiding of soft keyboard in Android dialog
1. Write in front
The main content of this article is about the display and hiding of the soft keyboard in dialog. The requirement is that there is a password input box in dialog to pop up the dialog display soft keyboard and close the dialog hide soft keyboard.
Well, isn't it a little simple, but I still encountered some problems in the implementation process. After trying most of the methods on the Internet, I finally found a good method to share with you.
Look at the renderings below:
@H_ 502_ 15@
2. Implementation process
Let's talk about the initial implementation method:
But, the soft keyboard is not displayed. There are two methods to display the soft keyboard. The first method is used, and the second method has no effect in dialog.
So I checked the source code of dialog and found that the display and hiding of dialog is handled by the handler. Is it because the method of displaying the soft keyboard is too fast? So I delayed displaying the soft keyboard after the show method and found that it can be displayed normally.
But the method of delaying processing is obviously not very good. Is there a method that can call back after the dialog is displayed? Well, yes, setonshowlistener method. Just display the soft keyboard in Onshow, the callback method of onshowlistener interface. The soft keyboard can be hidden after disassiss or in the callback method ondississ.
Delay display soft keyboard
3. Code
Display dialog prompt box
Method for displaying and hiding soft keyboard
Call the method that displays the dialog
4. Write at the end
In the test of frequently displaying and closing dialog, it is found that sometimes the soft keyboard will not display, but the law is not found. Students with understanding can leave me comments.
Full demo download
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.