android - 键盘打开时如何向上滑动活动?
问题描述
键盘与登录页面上的电子邮件 EditText 冲突。我想在键盘打开时在欢迎回来和描述文本上方滑动。
当前状态:https ://i.hizliresim.com/135sizd.png 我想要什么:https ://i.hizliresim.com/pgacbn2.png
我使用了adjustpan和adjustresize,但没有用。我在等你的帮助。谢谢你。
这是我的 XML 代码。
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="15dp"
android:background="@color/main_bg"
tools:context=".ui.auth.LoginActivity">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:isScrollContainer="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:fontFamily="@font/i_d_semibold"
android:letterSpacing="-0.001"
android:text="@string/login_header"
android:textColor="@color/header"
android:textSize="22sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:fontFamily="@font/i_d_light"
android:text="@string/login_description"
android:textColor="@color/description"
android:textSize="14sp"
android:textStyle="bold" />
<EditText
android:layout_width="match_parent"
android:layout_height="47dp"
android:layout_marginTop="20dp"
android:background="@drawable/input_bg"
android:drawableStart="@drawable/mail_ic"
android:drawableEnd="@drawable/check_ic"
android:drawablePadding="20dp"
android:fontFamily="@font/i_d_regular"
android:hint="@string/email"
android:inputType="textEmailAddress"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:textColor="@color/header"
android:textColorHint="@color/description"
android:textSize="14sp" />
<EditText
android:layout_width="match_parent"
android:layout_height="47dp"
android:layout_marginTop="10dp"
android:background="@drawable/input_bg"
android:drawableStart="@drawable/password_ic"
android:drawableEnd="@drawable/eye_ic"
android:drawablePadding="20dp"
android:fontFamily="@font/i_d_regular"
android:hint="@string/password"
android:inputType="textPassword"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:textColor="@color/header"
android:textColorHint="@color/description"
android:textSize="14sp" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="250dp"
android:textSize="13sp"
android:layout_height="wrap_content"
android:text="@string/terms_of_service"
android:textColor="@color/description"
android:gravity="center" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1"
android:layout_marginBottom="10dp"
android:gravity="center" >
<com.google.android.material.button.MaterialButton
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_marginTop="10dp"
app:cornerRadius="10dp"
android:text="@string/get_started"
android:textColor="@color/white"
android:layout_weight="0.45"
app:strokeColor="@color/white"
android:fontFamily="@font/i_d_semibold"
android:textAllCaps="false"
android:letterSpacing="-0.001"
app:strokeWidth="2dp"
app:backgroundTint="@color/main_bg"
/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0.02" />
<com.google.android.material.button.MaterialButton
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_marginTop="10dp"
app:cornerRadius="10dp"
android:layout_weight="0.45"
android:text="@string/login"
android:fontFamily="@font/i_d_bold"
android:textAllCaps="false"
android:letterSpacing="-0.001"
app:backgroundTint="@color/main_button"
/>
</LinearLayout>
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
解决方案
加入AndroidManifest.xml
android:windowSoftInputMode="adjustPan|adjustResize"
更改您onCreate() method
的activity class
类似内容
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
推荐阅读
- r - 如何从 R 中的数字中选择第 n 个数字?
- sql - 查找不同年份的缺失部分数据
- python - 将 csv 文件上传到 cassandra(语法错误)
- git - 如何在已经存在的本地 git 存储库上设置 Visual Studio 2019?
- sql - 如何计算同一项目的多行?
- javascript - Google 登录 API - 附加范围(Gmail 发送方式)
- php - WooCommerce 电子邮件模板中的 ACF 自定义字段
- database - 如何使用键从另一个表中插入数据?
- angular - ngClass 最佳实践中的角度参考 id
- java - 双击 jtable 的错误行为