T
T
TheMatiss2016-03-16 02:45:59
Android
TheMatiss, 2016-03-16 02:45:59

Why is no text entered in android webview?

A small webview based android app that loads a page from the web.
The page has a text input field input type=text (or textarea , the result is the same).
When you click on input , you can clearly see that it is in focus (the frame turns blue), the keyboard appears, however, there is no cursor and no text is entered. On the keyboard itself, there are hints as you type, as usual, but the value does not change and the text is not visible.
Help me figure out what's wrong. I did not find an answer on stackoverflow that would solve this problem.
Thank you!
Java

package ru.bnizov.project1;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import java.util.Random;
import ru.bnizov.project1.R;

public class MainActivity extends Activity {

    private WebView mWeb;

    private class WebViewer extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading (WebView view, String url) {
            view.loadUrl(url);
            return true;
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            view.loadUrl(String.format("file:///android_asset/web_error.html"));
        }


    }

    Random randNumber = new Random();
    int lt = randNumber.nextInt(999) + 1;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mWeb=(WebView)findViewById(R.id.web);
        mWeb.setWebViewClient(new WebViewer());

        WebSettings settings = mWeb.getSettings();
        mWeb.getSettings().setLoadWithOverviewMode(true);
        mWeb.getSettings().setUseWideViewPort(true);

        mWeb.getSettings().setJavaScriptEnabled(true);
        mWeb.setOverScrollMode(View.OVER_SCROLL_NEVER);

        mWeb.requestFocus(View.FOCUS_DOWN);
        mWeb.setOnTouchListener(new View.OnTouchListener(){
            @Override
            public boolean onTouch(View v, MotionEvent event){
                switch (event.getAction()){
                    case MotionEvent.ACTION_DOWN:
                    case MotionEvent.ACTION_UP:
                        v.requestFocusFromTouch();
                        break;
                }
                return false;
            }
        });

        mWeb.loadUrl("http://***.ru?" + lt);
    }

    // Выход после подтверждения после нажатия кнопки Назад
    @Override
    public void onBackPressed() {
        new AlertDialog.Builder(this)
        .setMessage("Выйти?")
        .setCancelable(true)
        .setPositiveButton("Да", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                finish();
            }
        }).setNegativeButton("Нет", null).show();
    }

}

XML
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:id="@+id/web"
    android:scrollbars="none"/>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question