Android monitor soft keyboard pop-up and hidden sample code

Situation: there is a Scrollview in the layout file, an editview in the Scrollview, and a control at the bottom of the layout (see the layout code below). As soon as the program starts editview, it will get the focus, pop up the soft keyboard, and push up the control at the bottom. It doesn't feel very good, so I want to listen to the soft keyboard pop-up, and hide the bottom control at this time, When the soft keyboard is hidden, the bottom control is displayed.

Initial:

The Android API provides a way to pop up and hide the soft keyboard, such as

However, it does not provide a method to monitor the pop-up and hiding of the soft keyboard.

Because pop-up and hiding the soft keyboard will inevitably lead to changes in the layout. Listen to the changes in the layout and calculate the offset to calculate whether to show or hide the keyboard. There are two solutions.

1. Customize the view and modify the onlayout () method, such as

2. Get the height change of the ViewGroup in the activity

Aside: during the test, it is found that by setting full screen getwindow(). Setflags (WindowManager. Layoutparams. Flag_fullscreen, WindowManager. Layoutparams. Flag_fullscreen); You can achieve the same goal, but full screen is against my original intention. I personally recommend the second method, because the first method is not easy to use when a customer's device opens the photo album lock of fingerprint identification.

In the process of checking the data, we see that some developers want to top the bottom control when the soft keyboard pops up. The method is the same as above.

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.

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