developer tip

WebView에서 양식 필드를 탭하면 소프트 키보드가 표시되지 않습니다.

copycodes 2021. 1. 10. 17:29
반응형

WebView에서 양식 필드를 탭하면 소프트 키보드가 표시되지 않습니다.


내 WebView를 만들고 WebChromeClient 및 WebViewClient 개체를 설정했습니다. 이 WebView를 시작하면 HTML 양식 필드를 터치하면 반응하지만 (커서가 나타남) 선택되지 않고 소프트 키보드가 시작되지 않습니다. 트랙볼을 사용하여 양식을 선택하고 누르면 키보드가 나타납니다.

이 답변이 제안한 myWebview.requestFocusFromTouch()대로 전화를 걸 었지만 거짓을 반환하고 도움이되지 않습니다.


http://code.google.com/p/android/issues/detail?id=7189

다른 사람이 명확하지 않은 경우 수정 사항이 있습니다.

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

Dv_MH의 답변에 10 % 동의했습니다. 그러나 첨부 된 클래스는 약간 과도했습니다. 내가해야 할 일은 WebView를 확장하고 onCheckIsTextEditor ()에 대해 true를 반환하는 것뿐입니다.

import android.content.Context;
import android.util.AttributeSet;
import android.webkit.WebView;

public class LiveWebView extends WebView {

    public LiveWebView(Context context) {
        super(context);
    }

    public LiveWebView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public LiveWebView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public boolean onCheckIsTextEditor() {
        return true;
    }
}

거기에서 일반 WebView (대화 상자에서도)로 사용할 수있었습니다.

또는 더 적은 코드로 :

WebView web = new WebView(context) {
  @Override
  public boolean onCheckIsTextEditor() {
    return true;
  }
};

중요 저는 이것을 검색하는 데 몇 시간을 보냈고 "ViewGroup"을 확장하는 부모 레이아웃에 속성이 없는지 확인하여 해결했습니다.

android : descendantFocusability = "blocksDescendants"는 자식 레이아웃에 초점이 맞춰지지 않도록합니다.

또는 webview에 android : focusable = "true"추가


AndroidChen의 답변이 전혀 작동하지 않았지만 제공된 링크 ( http://code.google.com/p/android/issues/detail?id=7189 )를 검색 했고 다음 클래스를 찾았습니다. 완벽하게 작동합니다 ( HTC Bravo의 Android Froyo), 텍스트뿐만 아니라 모든 버튼, 리디렉션 등 모든 것이 완벽하게 작동합니다.

class LiveWebView extends WebView
{
    Context mContext;

    public LiveWebView(Context context, String URL)
    {
        super(context);
        mContext = context;
        setWebViewClient(URL);
    }

    @Override
    public boolean onCheckIsTextEditor()
    {
        return true;
    }

    @SuppressLint("SetJavaScriptEnabled")
    boolean setWebViewClient(String URL)
    {
        setScrollBarStyle(SCROLLBARS_INSIDE_OVERLAY);
        setFocusable(true);
        setFocusableInTouchMode(true);
        requestFocus(View.FOCUS_DOWN);

        WebSettings webSettings = getSettings();
        webSettings.setSavePassword(false);
        webSettings.setSaveFormData(false);
        webSettings.setJavaScriptEnabled(true);
        webSettings.setSupportZoom(false);
        webSettings.setUseWideViewPort(false);

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

        this.setWebViewClient(new WebViewClient()
        {
            ProgressDialog dialog = new ProgressDialog(mContext);

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url)
            {
                loadUrl(url);

                return true;
            }

            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
            {
                Toast.makeText(mContext, "Oh no! " + description, Toast.LENGTH_SHORT).show();
            }

            public void onPageStarted(WebView view, String url, Bitmap favicon)
            {
                if (dialog != null)
                {
                    dialog.setMessage("Loading...");
                    dialog.setIndeterminate(true);
                    dialog.setCancelable(true);
                    dialog.show();
                }

            }

            public void onPageFinished(WebView view, String url)
            {
                if (dialog != null)
                {
                    dialog.cancel();
                }
            }
        });

        this.setWebChromeClient(new WebChromeClient()
        {
            public void onProgressChanged(WebView view, int progress)
            {
                // Activities and WebViews measure progress with different scales.
                // The progress meter will automatically disappear when we reach 100%
            }

            @Override
            public boolean onJsAlert(WebView view, String url, String message, JsResult result)
            {
                result.confirm();
                return true;
            }
        });

        loadUrl(URL);

        return true;
    }
}

그런 다음 대화 상자 내에서 웹보기를 만들기 위해이 코드를 작성했습니다.

AlertDialog.Builder alert = new AlertDialog.Builder(M_PaymentOptions.this);
alert.setNegativeButton("Back to Payment Options", new DialogInterface.OnClickListener()
{
    @Override
    public void onClick(DialogInterface dialog, int id)
    {}
});

alert.setTitle("BarclayCard Payment");

LiveWebView liveWevViewObject = new LiveWebView(M_PaymentOptions.this, redirecturl);

alert.setView(liveWevViewObject);

alert.show();

WebView 아래에 보이지 않는 EditText를 추가하십시오.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:visibility="invisible" />

<WebView
    android:id="@+id/webView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

All these focus-related solutions didn't work on my Samsung Note 3/Android 5.0

ReferenceURL : https://stackoverflow.com/questions/4200259/tapping-form-field-in-webview-does-not-show-soft-keyboard

반응형