[英]Android move footer up when keyboard is open
I'm designing a login html page which is loaded into an Android WebView. 我正在设计一个登录HTML页面,该页面已加载到Android WebView中。 There are two text areas and a "Login" button fixed to the bottom of the page.
页面底部固定有两个文本区域和一个“登录”按钮。 My problem is that when the person types into the text area;
我的问题是,当该人键入文本区域时; the keyboard pops up and hides the login button.
键盘弹出并隐藏登录按钮。
How can I keep the "Login" button fixed to the bottom of the page but to the top of the keyboard? 如何将“登录”按钮固定在页面底部但固定在键盘顶部?
I've tried : 我试过了 :
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
And 和
android:windowSoftInputMode="adjustPan|adjustResize"
Neither makes a difference. 两者都没有影响。
What you'll need to do is place your button inside of a RelativeLayout
and then give it the following attributes: 您需要做的是将按钮放在
RelativeLayout
,然后为其指定以下属性:
android:layout_alignParentBottom="true"
When the screen resizes for the keyboard, the button will be pushed up with the keyboard because RelativeLayout
adjusts for remaining screen space. 当为键盘调整屏幕大小时,由于
RelativeLayout
针对剩余的屏幕空间进行调整,因此按钮会随键盘向上推。
Here's a full working code sample with one button: 这是一个带有一个按钮的完整工作代码示例:
<!--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>
EDIT 编辑
To fix a an element to the bottom of a page in a web page, you'll need to make the following modifications to the html/css. 要将元素固定到网页页面的底部,您需要对html / css进行以下修改。
.login-button {
position: fixed;
bottom: 0;
width: 100%;
}
Button text 按钮文字
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.