Клавиша Backspace не удаляет тайские гласные при вводе текста Html веб-просмотра

Я использую Android Studio 2.1.1.

Я открываю локальный html-файл с вводом текста типа в своем веб-просмотре. Я обнаружил, что клавиша возврата на динамической клавиатуре не удаляет ни одну из тайских гласных, которые находятся над или под согласной буквой. Однако в представлении EditText клавиша возврата не имеет проблем с тайскими гласными. Он удаляет все символы, как тайские согласные, так и гласные.

MainActivity.java

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final EditText simpleEditText = (EditText) findViewById(R.id.simpleEditText);
    WebView wv = (WebView)findViewById(R.id.webview);
    wv.loadUrl("file:///android_asset/test_input.html");
    }
}

Activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.thongjoon.edittext.MainActivity">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@id/simpleText"
    android:text="Hello World!"/>

<EditText
    android:id="@+id/simpleEditText"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/simpleText"
    android:hint="Enter Your Name Here" />
<WebView android:id="@+id/webview"
         android:layout_below="@id/simpleEditText"
         android:layout_width="fill_parent"
         android:layout_height="50dp"/>

</RelativeLayout>

test_input.html

<!doctype html>
<html lang="th">
   <head>
   <meta charset="utf-8">
   <title>Document</title>
   </head>
<body>
  ทดสอบ<input type="text" name="yourname" value="Your Name"><br>
</body>
</html>

Я новичок в Android. Я действительно не знаю, как решить эту проблему. Пожалуйста, порекомендуйте.


person tjkh    schedule 06.11.2016    source источник


Ответы (1)


Я решил не использовать html-ввод типа text. Вместо этого я создал класс JavaScriptInterface для передачи переменной функции javascript. Переменная из представления EditText. Я передаю его по нажатию кнопки.

Activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.thongjoon.edittext.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@id/simpleText"
        android:text="Hello World!"/>

    <EditText
        android:id="@+id/simpleEditText"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/simpleText"
        android:singleLine="true"
        android:maxLength="20"
        android:hint="Enter Text Here" />
    <Button
        android:id="@+id/btnSearch"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/simpleEditText"
        android:text="Go"/>

    <WebView android:id="@+id/webview"
         android:layout_below="@+id/btnSearch"
         android:layout_width="fill_parent"
         android:layout_height="150dp"/>

</RelativeLayout>

test_input.html

<!doctype html>
<html lang="th">
<head>
  <meta charset="utf-8">
  <title>Document</title>

</head>
<body>

  ทดสอบการส่งตัวแปรจาก Android<br>
  Passing a variable from Android to Javascript<br>

  <script>
    function init(val){
      alert(val);
    }
  </script>
</body>

JavaScriptInterface.java

import android.content.Context;
import android.webkit.JavascriptInterface;

public class JavaScriptInterface {
    Context mContext;
    JavaScriptInterface(Context c) {
        mContext = c;
    }
    @JavascriptInterface
    public static String getFromAndroid(String myVar) {
        return myVar;
    }
}

MainActivity.java

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

    String inputText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // hide virtual keyboard. Show keyboard when user touches EditText view
        getWindow().setSoftInputMode(
            WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN
        );

        setContentView(R.layout.activity_main);

        final EditText simpleEditText = (EditText) findViewById(R.id.simpleEditText);
        final Button btn_search =(Button) findViewById(R.id.btnSearch);

        final WebView webView = (WebView)findViewById(R.id.webview);
        WebSettings settings = webView.getSettings();
        settings.setJavaScriptEnabled(true);
        //for showing Javascript alert box
        webView.setWebChromeClient(new WebChromeClient() {});
        webView.addJavascriptInterface(new JavaScriptInterface(this), "Android");
        webView.loadUrl("file:///android_asset/test_input.html");

        btn_search.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                //hide virtual keyboard
                InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                       inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            inputText = simpleEditText.getText().toString();
            webView.loadUrl("javascript:init('" + inputText + "')");
            }
        });
    }
}

Большое спасибо за следующие ссылки;

Передача данных из класса java в веб-представление html

Получить значение поля редактирования текста Как передать значение/переменную из Java-класс Android в файл javascript/.html в Android 4.4.2 kitkat

Передача данных из класса java в веб-представление html

person tjkh    schedule 07.11.2016