Skip to content Skip to sidebar Skip to footer

Show Soft Keyboard In Alertdialog With A Webview Inside (android)

In my Android app I create an AlertDialog that has a WebView inside. The WebView loads a webpage that requires the user to log in. However, when I click on text fields in the WebVi

Solution 1:

It seems that the best solution is to simply create a custom dialog. Custom dialogs do not appear to have the soft keyboard bug at all (it shows up exactly when it has to). Here's some basic code:

Dialogdialog=newDialog(this);
dialog.requestWindowFeature(Window.FEATURE_LEFT_ICON);
dialog.setContentView(R.layout.dialog);
dialog.setTitle("My great title");
dialog.setCancelable(true);

dialog.show();
dialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.icon);

WebViewvw= (WebView) dialog.findViewById(R.id.wv);

Solution 2:

There much better solution (with AlertDialog).

  1. Extend WebView class.

    publicstaticclassLocalWebViewextendsWebView {
        publicLocalWebView(Context context) {
            super(context);
        }
    
        publicLocalWebView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        publicLocalWebView(Context context, AttributeSet attrs, int defStyleAttr) {
            super(context, attrs, defStyleAttr);
        }
    
        @TargetApi(Build.VERSION_CODES.LOLLIPOP)publicLocalWebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
            super(context, attrs, defStyleAttr, defStyleRes);
       }
    
        publicLocalWebView(Context context, AttributeSet attrs, int defStyleAttr, boolean privateBrowsing) {
            super(context, attrs, defStyleAttr, privateBrowsing);
        }
    
        @OverridepublicbooleanonCheckIsTextEditor() {
            returntrue;
        }
    }
    
  2. Use this LocalWebView instead of origin WebView in layout that you set to AlertDialog as content view.

Solution 3:

If it's still relevant, for me the problem was related to an immersive dialog + webview.

I've override the dialog show method to achieve immersive by setting a flag - NOT FOCUS on the dialog window, once I removed it I lost the immersivnes but now my web dialog pops uo the keyboard...

Post a Comment for "Show Soft Keyboard In Alertdialog With A Webview Inside (android)"