Android soft Keyboard not open in webView`

后端 未结 5 617
轻奢々
轻奢々 2021-02-08 04:56

I m Using WebView in AlertDialog to authenticate user to twitter. but When i click on field in webview ,android keyboard doesnt open. here is my code that shows how i added webv

5条回答
  •  面向向阳花
    2021-02-08 05:42

    Here is my solution to this problem:

    Put a dummy edit text, and set it's visibility to GONE, and add it to a containing LinearLayout, after adding the WebView to the layout.

    Example:

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    
    LinearLayout wrapper = new LinearLayout(this);
    WebView webView = new WebView(this);
    EditText keyboardHack = new EditText(this);
    
    keyboardHack.setVisibility(View.GONE);
    
    webView.loadUrl(url);
    
    wrapper.setOrientation(LinearLayout.VERTICAL);
    wrapper.addView(webView, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
    wrapper.addView(keyboardHack, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);              
    
    builder.setView(wrapper);
    
    builder.create().show();
    

    Once this is done, everything should work properly, and when you select an item in the WebView, the keyboard appears as expected.

提交回复
热议问题