2
Is there any way to change a form field by taking the Edittext value, using a Webview client ?
I have an application in which accesses my site and there are 2 fields, a user and another password, when I type in "Edittext" the user and password, I need this value to pass to the html form.
Follow the code of the class responsible for opening the site:
public class Site extends Tela1 {
static WebView site;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_website);
site = (WebView) findViewById(R.id.web);
WebSettings settings = site.getSettings();
settings.setJavaScriptEnabled(true);
settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(true);
settings.supportZoom();
settings.setBuiltInZoomControls(true);
settings.setTextZoom(150);
settings.setSupportZoom(true);
settings.setDomStorageEnabled(true);
site.setWebChromeClient(new WebChromeClient());
site.loadUrl("javascript:var elem = document.getElementById('user').value = 'My default value';");
MyWebViewClient cliente = new MyWebViewClient();
cliente.shouldOverrideUrlLoading(site, dadosDominio.trim());
}
private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}
HTML CODE:
<form novalidate id="login_form" action="/login/" method="post" target="_top">
<div class="input-req-login"><label for="user">Nome de usuário</label></div>
<div class="input-field-login icon username-container">
<input name="user" id="user" autofocus="autofocus" value="" placeholder="Digite seu nome de usuário." class="std_textbox" type="text" tabindex="1" required>
</div>
<div style="margin-top:30px;" class="input-req-login"><label for="pass">Senha</label></div>
<div class="input-field-login icon password-container">
<input name="pass" id="pass" placeholder="Digite a senha da conta." class="std_textbox" type="password" tabindex="2" required>
</div>
<div class="controls">
<div class="login-btn">
<button name="login" type="submit" id="login_submit" tabindex="3">Login</button>
</div>
</div>
<div class="clear" id="push"></div>
</form>
LOG:
I/chromium: [INFO:library_loader_hooks.cc(112)] Chromium logging enabled: level = 0, default verbosity = 0
I/BrowserProcessMain: Initializing chromium process, renderers=0
W/chromium: [WARNING:proxy_service.cc(888)] PAC support disabled because there is no system implementation
W/AwContents: nativeOnDraw failed; clearing to background color.
I/chromium: [INFO:CONSOLE(1)] "Uncaught TypeError: Cannot set property 'value' of null", source: (1)
I/chromium: [INFO:async_pixel_transfer_manager_android.cc(56)] Async pixel transfers not supported
I/chromium: [INFO:async_pixel_transfer_manager_android.cc(56)] Async pixel transfers not supported
The id
user
exists ?– ramaral
Yes, there is. I’ve now put the HTML code up for you to see if I’m doing something wrong..
– Diego Kappaun