Android WebView input box keyboard does not pop up, androidwebview
When using embedded WebView to load HTML web pages in Android, if an input box exists in the html page. In some mobile phone devices, when the input box gets the focus, the keyboard of the system input method cannot pop up correctly, thus the normal input requirements cannot be fulfilled.
I also encountered this problem when I was working on the APP. The following is my solution. It may not be suitable for your situation, but it is worth learning ~
WebView setting problems sometimes the html page we designed cannot be well adapted to WebView, especially when our html page is designed for a PC browser, when WebView is used for loading, the interface may be disordered. When the input box is overwritten by other elements (such as div), the input method will not pop up even if the input can be displayed and selected. What we can do in this case is
1. WebView. getSettings (). setUseWideViewPort (true) enables WebView to adapt to the screen size of mobile phones and scale freely. This makes WebView more similar to PC browsers and avoids UI layout disorder, reduce the probability of a problem 2. Provide a mobile version for html
Sometimes we need to customize WebView to meet specific requirements. For example, if we want to add a loading progress bar for WebView to unify the display of the WebView progress bar, the following code may appear:
Public class ProgressBarWebView extends WebView {
Public ProgressBarWebView (Context context ){ This (context, null ); } Public ProgressBarWebView (Context context, AttributeSet attrs ){ This (context, attrs, 0 ); } Public ProgressBarWebView (Context context, AttributeSet attrs, int defStyle ){ Super (context, attrs, defStyle ); // TODO // Your code }
} |
What is the problem with this code? When ProgressBarWebView is used, if the style is not specified in layout
Public ProgressBarWebView (Context context, AttributeSet attrs ){ This (context, attrs, 0 ); } |
In the constructor, we specify 0 here. If you want to view the source code of Android WebView, it is defined as follows:
public WebView(Context context, AttributeSet attrs) { this(context, attrs, com.android.internal.R.attr.webViewStyle); } |
The com. android. internal. R. attr. webViewStyle style must be appended to WebView. Otherwise, WebView cannot work normally.
The above are some of the methods I have summarized and hope to help you ~