I have a webview with a credit card entry form (with standard <input type="text" />
fields). In different versions of Android I get different keyboards. Kit-Kat seems to not show Prev / Next keys when inside the form.
Example without Prev / Next:
Same webview, with Prev / Next:
The WebView class is an extension of Android's View class that allows you to display web pages as a part of your activity layout. It does not include any features of a fully developed web browser, such as navigation controls or an address bar. All that WebView does, by default, is show a web page.
Alternatives to WebView If you want to send users to a mobile site, build a progressive web app (PWA). If you want to display third-party web content, send an intent to installed web browsers. If you want to avoid leaving your app to open the browser, or if you want to customize the browser's UI, use Custom Tabs.
This example demonstrate about How to enable webview java script in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.
This interface was deprecated in API level 12. This interface is now obsolete.
You can control the keyboard from the WebView, but as other answers suggest it may not work with every keyboard ever made. Despite that, I typically find most mainstream keyboards have implemented the behaviour I want.
The WebView has a method called onCreateInputConnection
. You can hook into this method and add (and/or remove) flags to the inputType
and/or imeOptions
. There are many flags available to you.
Check out the EditorInfo options, in particular IME_FLAG_NAVIGATE_NEXT and IME_FLAG_NAVIGATE_PREVIOUS. See usage below (which removes the prev/next flags from the keyboard options):
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
InputConnection inputConnection = super.onCreateInputConnection(outAttrs);
outAttrs.imeOptions = outAttrs.imeOptions & ~EditorInfo.IME_FLAG_NAVIGATE_NEXT &
~EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS;
return inputConnection;
}
Another thing you could try is to hide the entire suggestions bar using the InputType flags TYPE_TEXT_FLAG_NO_SUGGESTIONS
. See example below (which adds the "no suggestions" flag to the input type):
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
InputConnection inputConnection = super.onCreateInputConnection(outAttrs);
outAttrs.inputType = outAttrs.inputType | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
return inputConnection;
}
There are many other flags available to have a play with to customise the IME directly from the WebView. Refer the developer to the linked pages and you should hopefully be able to achieve the behaviour you are after on most keyboards.
You do have some minimal control, but not that much. The type of the control (passowrd, numeric, text) will be sent to the soft keyboard and used to change how things are displayed. However, the choices the keyboard makes based on those options are keyboard specific- the Google keyboard reacts differently than Swype, which reacts differently than Swiftkey, which reacts differently than the Samsung keyboard, etc. You can't really count on a specific behavior.
Tried on Android Studio 3.0 (SDK API 26), the answer https://stackoverflow.com/a/23462658/3286489 crashes. After search further found this working.
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
InputConnection inputConnection = new BaseInputConnection(this, true);
outAttrs.imeOptions = outAttrs.imeOptions & ~EditorInfo.IME_FLAG_NAVIGATE_NEXT &
~EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS;
return inputConnection;
}
And
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
InputConnection inputConnection = new BaseInputConnection(this, true);
outAttrs.inputType = outAttrs.inputType | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
return inputConnection;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With