0

I have a set of AlertDialog's which I can go back and forth. Dialog A, Dialog B(has HTML content) and Dialog C. On dialog B I have added a web view to show some HTML content, I want to disable keyboard from popping up on this perticular dialog B. HTML content does not have any edit text's. I have used "getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)" which does the job the first time the dialog is opened. When I navigate for the first time from dialog A to dialog B, dialog B does not pop up the keyboard. When I come back to dialog B from A or C the keyboard starts popping up when i swipe on the HTML content.

HTML content is a touch based content.

I am assuming that the code for hiding keyboard is not executed every time the dialog is opened.

I have tried "SOFT_INPUT_STATE_ALWAYS_HIDDEN" and "SOFT_INPUT_STATE_HIDDEN".

EDIT : If I opened google on the web view which has a text field for search. key board does not popup when I touch the edit text which is good even though i navigate. But when I try to scroll up and down on the page the keyboard pops up and disappears(Happens from the second visit to the dialog).

Could you please share your thoughts on how to hide the keyboard every time I open this dialog B.

@Override
@Deprecated
protected Dialog onCreateDialog(int id) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this,R.style.AlertDialogCustom);
    final  Boolean pinVerficationDialogPopedUp = loginData.getBoolean("pinVerficationDialogPopedUp",
            false);

    if (pinVerficationDialogPopedUp == false) {
        switch (id) {
            case DIALOG_ADD_A_PERSON_BODY_MAP:
             try {
                    LayoutInflater inflaterBodyMap = this
                            .getLayoutInflater();
                    final View inflatorBodyMap = inflaterBodyMap
                            .inflate(
                                    R.layout.dialog_incident_window_body_map,
                                    null);
                    bodyMapWebView  = (WebView) inflatorBodyMap.findViewById(R.id.webView);

                    bodyMapWebView.getSettings().setJavaScriptEnabled(true);
                    bodyMapWebView.getSettings().setBuiltInZoomControls(true);
                    bodyMapWebView.getSettings().setSupportZoom(true);

                    /*
                    Trying to resolve issue where sometimes when the HTML page loads, it does
                    not load the whole content
                     */
                    bodyMapWebView.post(new Runnable() {
                        @Override
                        public void run() {
                            bodyMapWebView.loadUrl("file:///android_asset/bodyMap.html");
                        }
                    });

                    bodyMapWebView.addJavascriptInterface(new WebAppInterface(this), "Android");
                    builder.setTitle("Injured person");
                    builder.setView(inflatorBodyMap);
                    builder.setPositiveButton("Next",
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog,
                                                    int which) {
                                                    //next dialog


                                }
                            });
                    builder.setNegativeButton("Back",
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog,
                                                    int which) {
                                   //previous dialog

                                }
                            });
                    alertBodyMap = builder.create();
                    alertBodyMap.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
                    alertBodyMap.show();
                    return dialog;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }   
        return dialog
        }

Your help much appreciated. Thank you

BRDroid
  • 3,920
  • 8
  • 65
  • 143
  • http://stackoverflow.com/a/1662088/527759 – Eugene Popovich Aug 13 '15 at 10:25
  • Hi user527759 I do not have any edit texts on the dialog, I only have a web view within a Linear layout. I have tried the link with focusable true for Linear layout but it does not solve. – BRDroid Aug 13 '15 at 10:34

1 Answers1

0

The issue was with the Zoom control feature on the webview.

I had used the bellow code for zoom control. bodyMapWebView.getSettings().setBuiltInZoomControls(true); bodyMapWebView.getSettings().setSupportZoom(true);

I disabled the display of zoom controls so we can only pinch zoom using the bellow code.

 bodyMapWebView.getSettings().setBuiltInZoomControls(true);              
 bodyMapWebView.getSettings().setDisplayZoomControls(false);

This resolved the issue, webview no more pops up the keyboard.

To use the zoom control +/- I implemented ZoomControls in XML

 <ZoomControls android:id="@+id/zoomcontrols"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />

java code:

        zoomControls = (ZoomControls) inflatorBodyMap.findViewById(R.id.zoomcontrols);
                    /**
                     *
                     */
                    zoomControls.setOnZoomInClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            bodyMapWebView.zoomIn();
                        }
                    });
                    zoomControls.setOnZoomOutClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            bodyMapWebView.zoomOut();
                        }
                    });

Hope this helps other.

BRDroid
  • 3,920
  • 8
  • 65
  • 143