Android WebView input box keyboard does not pop up, androidwebview

Source: Internet
Author: User

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 ~




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.