【问题标题】:Android move footer up when keyboard is open键盘打开时Android将页脚向上移动
【发布时间】:2016-06-22 13:38:00
【问题描述】:

我正在设计一个加载到 Android WebView 中的登录 html 页面。 页面底部有两个文本区域和一个“登录”按钮。我的问题是当人输入文本区域时;键盘弹出并隐藏登录按钮。

如何将“登录”按钮固定在页面底部但在键盘顶部?

我试过了:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

还有

android:windowSoftInputMode="adjustPan|adjustResize"

两者都没有区别。

【问题讨论】:

  • 所以你想附加到底部的页脚是android视图或html网页的一部分??
  • 页脚是 HTML 页面的一部分,它被加载到全屏 android WebView 中。
  • @C0dekid 你能否扩展一下你的评论。
  • @C0dekid 我不明白这会有什么用。我并不想将整个 WebView 向上移动。我只希望页脚在 WebView 内向上移动。
  • 你可以为 webview 显示你的 xml 吗?谢谢!

标签: android html css webview


【解决方案1】:

您需要做的是将您的按钮放在RelativeLayout 内,然后为其赋予以下属性:

android:layout_alignParentBottom="true"

当屏幕为键盘调整大小时,按钮将随着键盘向上推,因为RelativeLayout 会调整剩余的屏幕空间。

这是一个完整的工作代码示例,只需一个按钮:

<!--Parent view-->
<RelativeLayout
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <!--Login Button-->
    <Button
        android:id="@+id/btnLogin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" />
</RelativeLayout>

编辑

要在网页中将元素固定到页面底部,您需要对 html/css 进行以下修改。

.login-button {
    position: fixed;
    bottom: 0;
    width: 100%;
}

按钮文字

【讨论】:

  • 我的按钮和登录页面是 WebView 中的 html。
  • 那么您可以访问网站的 html 和 css 吗?否则,您将无法使用任何 Android 命令完成您要查找的内容。
  • 是的,我可以访问它。
  • 对不起,我才发现你说登录按钮已经固定在屏幕底部了。问题是当键盘显示正确时,webview 窗口本身没有调整大小?如果是这样,您的应用是否设置为全屏?
  • WebView 是全屏的并且很好。我只希望当键盘打开时页脚 div 在 WebView 内向上移动,我不希望 WebView 移动。对不起,很难解释。我认为这更像是一个 html-web 问题,而不是特定于 Android 的问题。
【解决方案2】:

我知道我回答这个问题有点晚了(5 年),但我刚刚遇到了这个问题,并想把我的解决方案放在这里,以防其他人仍在寻找答案。 .. 这更像是一个 HTML/CSS 问题,我通过将页脚包装在容器中并使用以下 CSS 解决了它

.container {
  position: relative;
},

.footer {
  width: 100%;
  position: absolute;
  bottom: 0;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-19
    • 1970-01-01
    • 2016-12-17
    • 2022-10-09
    • 1970-01-01
    • 2019-12-20
    • 2012-09-29
    相关资源
    最近更新 更多