Specific implementation code of Android floating edit box
During the development of android app, we often encounter the demand that some input boxes should be suspended above the soft keyboard. The general methods are as follows.
Android input method soft keyboard is suspended. The most common method is to add viewtreeobserver.ongloballayoutlistener to viewtreeobserver. When the global layout is completed or the visibility of the view in the view tree changes, call back the ongloballayout method to obtain the area of the current window in the ongloballayout method, If the area height exceeds one fifth of the screen, it is generally considered that the soft keyboard is in the display state, and the area height is the height of the input method soft keyboard. The height of the view is dynamically adjusted through this height to achieve the effect that the input box is suspended above the soft keyboard. The code is as follows:
Another way is to set Android: windowsoftinputmode = "statevisible|adjustresize" for activity, but this method is not very flexible and generally can not solve the needs of products.
This article focuses on achieving results through transparent activities.
Let's start with a rendering
design sketch
All the source code has been uploaded to GitHub. Click to view it. Don't forget star
1. Customize an activity theme
2. Set in androidmanifest.xml
3. adjust the gravity direction of window in Activity.
In this way, the effect of floating edit box is very simple. All the source code has been uploaded to GitHub and well encapsulated. You only need to realize your requirements layout, and there are complete usage examples.
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.