【问题标题】:Hide soft keyboard android application start up in phonegap在phonegap中隐藏软键盘android应用程序启动
【发布时间】:2017-09-14 13:28:03
【问题描述】:

我正在开发 phonegap 应用程序,但遇到了一些小问题,我尝试了所有方法,但没有任何效果..

我已经在 android 和 Iphone 中构建了应用程序,但我只在 android 中遇到了问题。软键盘会在应用程序启动时自动显示。

下面是我的html代码:-

<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 代码将在设备就绪事件上加载并重定向到另一个页面

  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>

【问题讨论】:

  • 应用加载时您是否专注于输入元素?只是为了检查添加“只读”属性到您的输入元素只是为了找到问题。
  • 感谢您的回复。实际上,当应用程序加载并尝试按照您的建议添加只读属性时,我并没有专注于输入元素,但这并没有帮助:(

标签: javascript jquery phonegap-plugins phonegap phonegap-cli


【解决方案1】:

您需要安装keyboard plugin

cordova plugin add cordova-plugin-keyboard

现在在设备就绪事件中隐藏键盘。

Keyboard.hide();

编辑 1:-

尝试在 androidmanifest.xml 中添加这一行

android:windowSoftInputMode="stateHidden|adjustPan"

希望这可能会有所帮助。

【讨论】:

  • 没有帮助:(
  • 需要更多代码而不是 html。我还需要查看 js 代码。应用程序启动时运行的代码。
  • 你对androidmanifest.xml做了什么改变吗???关于 android:windowSoftInputMode ???
  • 不,我应该在 androidmanifest 文件中添加什么来隐藏键盘?
  • 尝试在 android 清单中添加 android:windowSoftInputMode="stateHidden|adjustPan" 但没有帮助:(
猜你喜欢
  • 2013-10-24
  • 1970-01-01
  • 2011-08-24
  • 2011-09-01
  • 1970-01-01
  • 1970-01-01
  • 2022-12-14
  • 2015-06-29
  • 2011-02-17
相关资源
最近更新 更多