android网页浏览器和虚拟键盘

时间:2013-03-22 10:42:50

标签: android css html5 virtual-keyboard

我正在使用PhoneGap 2.5.0编写HTML5应用程序。

在应用的某些部分,例如搜索页面,当虚拟键盘出现时,它会缩小整个页面,因此我仍然可以在键盘正上方看到页脚。

然而,在应用程序的其他部分,如对话框,键盘覆盖页面,因此可能会覆盖一些字段。

我不在应用中使用任何“固定”定位元素。保持在同一个地方所需的所有元素都是“绝对的”。

键盘何时放在视图上以及何时收缩?到目前为止我找不到答案。

相关的HTML:

<body>
    <div role="dialog" id="details">
        <div class="popup-content">
            <header>
                <h1 role="heading">Details</h1>
            </header>
            <article>
                <div class="content">
                    <div class="label">Some Title</div>
                    <div id="dynamic_form">
                        <form><!-- dynamically filled form --></form>
                    </div>
                </div>
            </article>
            <footer>
                <ul class="footer-nav-buttons">
                    <li><a>Back</a></li>
                </ul>
            </footer>
        </div>
    </div>

    <page id="search">
        <header>
            <h1>Search</h1>
        </header>
        <article class="page-content">
            <div class="ui-header">
                <input name="searchterm" id="searchtermtextbox" value="" type="text">
            </div>
            <article>
                <div id="searchresultscontainer"></div>
            </article>
        </article>
    </page>

    <footer>
        <ul class="footer-nav-buttons main-navigation-bar">
            <li><a href="#menu" role="menuitem" class="button-menu"></a></li>
            <li><a href="#contacts" class="button-contacts"></a></li>
            <li><a href="#search" class="button-search"></a></li>
        </ul>
    </footer>
</body>

相关的CSS(还不完美,我稍后会尝试改进它,但它包含我正在使用的基本规则,不包括颜色,渐变,阴影等视觉风格):

body { margin: 0; position: absolute; height: 100%; width: 100%; }
page { position: absolute; top: 0; bottom: 0; left: 0; right: 0; display: none; }
page.selected { display: block; }
page>header { position: absolute; top: 0; left: 0; right: 0; height: 1cm; }
page article { position: absolute; top: 1cm; left: 0; bottom: 15mm; right: 0; }

div[role='dialog'] div.popup-content footer { position: relative; }
div[role='dialog'].visible { opacity: 1; z-index: 100; }
div[role='dialog'].active { display: -webkit-box; display: box; -webkit-box-align: center; }
div[role='dialog'] div.popup-content article { position: relative; }
div[role='dialog'] div.popup-content article div.content { position: relative; }

body>footer { position: absolute; bottom: 0; left: 0; right: 0; height: 15mm; }
ul.footer-nav-buttons { position: relative; display: -webkit-box; display: box; -webkit-box-align: center;
                        box-align: center; -webkit-box-pack: center; box-pack: center; list-style: none;
                        height: 100%; width: 100%; padding: 0; margin: 0;
                        -webkit-margin-before: 0;-webkit-margin-after: 0; -webkit-margin-start: 0;
                        -webkit-margin-end: 0; -webkit-padding-start: 0; }
ul.footer-nav-buttons li a { margin: 5px; }

1 个答案:

答案 0 :(得分:0)

解决此问题的最简单方法是使用输入焦点和模糊事件。

在jQuery中:

$("input").focus(function(){
    $('footer').hide();
});

$("input").blur(function(){
    $('footer').show();
});
相关问题