How to change values of HTML input with EditText using WebView?

2

Is there any way to change a form field by taking the value of EditText, using a WebView client? I have an application in which you access my website and there are 2 fields, one user and one password, when I type in the "EditText" user and password, I need this value to go to the html form.

Here is the code for 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
    
asked by anonymous 15.11.2015 / 05:23

0 answers