Why softkeyboard does not appear in Snippet using WebView

I use a compatibility package, and I have Fragmentone that returns WebViewin onCreateView. The problem is that the fragment is not added during onCreate Activity, and then when the text field is pressed inside the WebViewon-screen keyboard is not displayed. If the device was rotated after adding a custom web fragment, restoring activity, then the on-screen keyboard appears when you click on the text field.

Just to be clear. Here are two different scenarios.

public void onCreate(Bundle state){
   if(state == null){
      WebFragment web = new WebFragment();
      getSupportFragmentManager.beginTransaction().add(android.R.id.content, web).commit();
   }
}



public void onClick(View v){
      WebFragment web = new WebFragment();
      getSupportFragmentManager.beginTransaction().add(android.R.id.content, web).commit();
}

Activity onCreate WebView, , , . , -, -. - , , , , , .

+5
2

onCreateView

webview.setOnTouchListener(new View.OnTouchListener() {
    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;
    }
});  

android 2.3.3 3.2.0.

issue # 7189 fooobar.com/questions/131891/...

+11

RuslanK

, WebView

private class MyWebView extends WebView {

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

// Note this!
@Override
public boolean onCheckIsTextEditor() {
    return true;
}

@Override
public boolean onTouchEvent(MotionEvent ev)     {
    switch (ev.getAction())         {
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_UP:
            if (!hasFocus())
                requestFocus();
        break;
    }

    return super.onTouchEvent(ev);
}
}

xml :

<com.example.view.MyWebView
    android:id="@+id/vw"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

.., int int code...

MyWebView webView = (MyWebView) parent.findViewById(R.id.vw);
webView.setVerticalScrollBarEnabled(false);
webView.setHorizontalScrollBarEnabled(false);
webView.requestFocus(View.FOCUS_DOWN);
webView.loadUrl(url);
0

All Articles