我正在开发一个Android应用程序。它使用 WebView 加载具有以下组件的表单:
当我填写所有字段然后单击提交按钮时,数据将被验证,但是当我从 Android 键盘单击“Go”按钮时,什么也没有发生。我该如何解决?
P/S:我正在 android 4.4.4 设备上进行调试。
你必须使用html表单和javascript来控制提交。单击“Go”按钮即可提交表单;
<form>
<input type='text' id='user_id' />
<input type='password' id='password' />
<input type='button' id='btn_login' />
</form>
<script>
function login()
{
// login code here
}
$('btn_login').click(function() {
login();
});
$('form').submit(function() {
// this event fire on go button click.
login();
return false;
});
</script>
看看https://github.com/dx-luna/loena
javascript
function click(){
window.go_submit("user88","pass22")
}
golang
webview.Bind("go_submit", func(username string,password string){
println("user input, username : "+username+" password : "+password)
})
For that you need to handle button click event
view.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) {
Log.i(TAG,"Enter pressed");
//do whatever you were doing in submit button
}
return false;
}
});