Hide soft keyboard android application start up in phonegap

594 views Asked by At

I'm working on phonegap application and facing minor issue with it and tried everything but nothing works..

I've build application in android and Iphone but i'm facing issue in android only..soft keyboard is automatically showing up on start up of application.

below is my html code:-

<body>
<div id="page-transitions">
    <div class="header header-logo-center header-dark">
        <!-- <a href="#" class="header-icon header-icon-1 hamburger-animated open-sidebar-left"></a> -->
        <a href="index.html" class="header-logo"></a>
        <!-- <a href="#" class="header-icon header-icon-4 open-sidebar-right"><i class="ion-ios-email-outline"></i></a>     -->
    </div>

    <div id="page-content" class="page-content">
        <div id="page-content-scroll">
            <!--Enables this element to be scrolled -->
            <div class="page-fullscreen vertical-bg-3">
                <div class="page-fullscreen-content">
                    <div class="pageapp-login">

                        <div class="pageapp-login-input  animate-fade">
                            <i class="login-icon ion-person"></i>
                            <input id="username" type="email" value="Username" onfocus="if (this.value=='Username') this.value = ''" onblur="if (this.value=='') this.value = 'Username'">
                        </div>
                        <div class="pageapp-login-input  animate-fade animate-delay-100">
                            <i class="login-icon ion-asterisk"></i>
                            <input id="password" type="password" value="Password" onfocus="if (this.value=='Password') this.value = ''" onblur="if (this.value=='') this.value = 'Password'">
                        </div>
                        <div class="pageapp-login-links">
                            <!-- <a href="#" class="page-login-forgot"><i class="ion-ios-eye"></i>Forgot Credentials</a> -->
                            <a href="page-register.html" target="_self" class="page-login-create animate-right">Create Account<i class="ion-person"></i></a>
                            <div class="clear"></div>
                        </div>
                        <button id="btnSubmit" class="button button-green button-icon button-full half-top full-bottom  animate-zoom"><i class="ion-ios-arrow-thin-right"></i>Login</button>

                    </div>
                </div>
                <div class="overlay dark-overlay"></div>

            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
                    $(document).ready(function () {

                    }).on('deviceready', function () {
                        document.addEventListener("deviceready", 
 checkExistingSession, false);
                    });

js code will load on device ready event and redirect to another page

  function checkExistingSession() {

                        var userName = localStorage.getItem("username");
                        var password = localStorage.getItem("password");
                        var deviceType = localStorage.getItem("deviceType");
                        var deviceToken = localStorage.getItem("deviceToken");

                        var parameter = {
                            "username": userName,
                            "password": password,
                            "deviceType": deviceType,
                            "deviceToken": deviceToken
                        }

                        if (userName != null && password != null) {
                            $.ajax({
                                url: api_baseUrl + 'login',
                                type: "post",
                                data: JSON.stringify(parameter),
                                dataType: "json",
                                success: function (response) {
                                    // Inserting html into the result div on success

                                    if (response !== null && response.status === 1) {
                                        window.location = "dashboard.html";
                                    }
                                    else {
                                        window.location = "index.html";
                                        return false;
                                    }
                                }
                            });
                        }

                    }

   </script>
   </body>
1

There are 1 answers

8
Anuj.T On BEST ANSWER

You need to install the keyboard plugin.

cordova plugin add cordova-plugin-keyboard

Now on device ready event hide the keyboard.

Keyboard.hide();

Edit 1 :-

try adding this line in androidmanifest.xml

android:windowSoftInputMode="stateHidden|adjustPan"

Hope this might help.