简体   繁体   中英

Disabling Android Keyboard's 'Go' Button for WebView Text Entry

I am developing an Android application that uses a WebView pointed at a jQueryMobile-based site. Normally, disabling the 'Go' button on the soft keyboard is as simple as adding android:imeOptions="actionDone" to the control's XML tag. In the case of WebViews however, this doesn't do the trick.

How can I disable the 'Go' button from automatically doing a form submission, or alternatively to simply replace it with the 'Done' button, like android:imeOptions="actionDone" would for an EditText?

您可以通过放置表单的onsubmit事件来停止提交表单。

Here's a more detailed answer that uses the method alluded to by Vikas.

Since the problem is that your form is submitting, you can add an onSubmit attribute to your form element that runs JavaScript to determine if your form should be submitted.

Below is the form that you don't want to submit:

<form name="myForm" onSubmit="return doNothing()">
    <!-- Elements included in the form -->
</form>

And include this script that returns false which keeps your form from submitting.

<script>
function doNothing()
{
    return false;
}
</script>

Now, when you press Go after entering text into your text input field, the keyboard will simply collapse without submitting the form.

This could also be used to check for errors in your form. See the webpage below: http://www.htmlcodetutorial.com/forms/_FORM_onSubmit.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM