android - 隐藏某些字段的软键盘问题
问题描述
当键盘打开并隐藏编辑文本和按钮并且没有滚动时出现问题。我在互联网上搜索并找到了一些解决方案,例如添加到 AndroidManifest.xml android:windowSoftInputMode="stateHidden|adjustResize"
,ScrollView
在顶部(Login_Activity.xml),或者甚至fillViewport="true"
但它们都不适合我。
我有TabLayout
我的活动,在 TabLayout 中有 Login_Fragment.xml 和 editText 字段。这是我的代码:
显现:
<activity
android:name="com.ideomobile.common.ui.custom.WebViewActivity"
android:configChanges="orientation|keyboardHidden"
android:label="@string/app_name"
android:launchMode="singleTask"
android:screenOrientation="portrait" />
Login_Activity.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
android:weightSum="10">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:background="@color/BackgroundColor"
android:layoutDirection="rtl"
android:orientation="horizontal">
<ImageButton
android:id="@+id/imageButton_Info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="right|center_vertical"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@drawable/info_button"
android:clickable="true"
android:paddingRight="10dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:background="@drawable/logo" />
</RelativeLayout>
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="bottom"
android:layout_weight="1.5"
android:background="@color/BackgroundColor"
android:layoutDirection="rtl"
android:textColor="@color/finger_print_blue"
app:tabBackground="@drawable/tab_indicator_color"
app:tabGravity="fill"
app:tabIndicatorColor="@color/popups_blue_background"
app:tabIndicatorFullWidth="false"
app:tabMode="fixed" />
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="fill"
android:layout_marginBottom="0dp"
android:layout_weight="6.5"
android:background="@android:color/white"
android:paddingBottom="0dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/white"
android:gravity="center|bottom"
android:orientation="vertical">
<Button
android:id="@+id/buttonLogin"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_gravity="center_horizontal|center"
android:background="@color/login_button_disable"
android:enabled="false"
android:text="@string/login_button"
android:textAlignment="center"
android:textColor="@color/BackgroundColor"
android:textSize="11pt"
android:textStyle="bold" />
</LinearLayout>
Login_Fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/BackgroundColor"
android:orientation="vertical"
android:textDirection="rtl">
<LinearLayout
android:id="@+id/lines_for_finger_print"
android:layout_width="match_parent"
android:layout_height="80dp"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/finger_print_firat_line"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="20dp"
android:gravity="center"
android:text="@string/add_fingerprint_title_line_1"
android:textColor="@color/finger_print_blue"
android:textSize="11pt"
android:textStyle="bold" />
<TextView
android:id="@+id/finger_print_second_line"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="center"
android:text="@string/add_finger_print_title_line_2"
android:textColor="@color/text_login_fields"
android:textSize="8pt" />
</LinearLayout>
<EditText
android:id="@+id/editTextUserName"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_margin="20dp"
android:background="@drawable/edit_text_border"
android:cursorVisible="false"
android:digits="@string/fingerprint_digits_allows"
android:gravity="right|center_vertical"
android:hint="@string/user_name"
android:imeOptions="actionNext"
android:inputType="text"
android:textColor="@color/text_login_fields"
android:textColorHint="@color/text_login_fields"
android:textSize="11pt"
android:singleLine="true"/>
<EditText
android:id="@+id/editTextPassword"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@drawable/edit_text_border"
android:digits="@string/fingerprint_digits_allows"
android:gravity="right|center_vertical"
android:hint="@string/user_password"
android:imeOptions="actionNext"
android:inputType="textPassword"
android:paddingRight="20dp"
android:textColorHint="@color/text_login_fields"
android:textSize="11pt"
android:singleLine="true"/>
<TextView
android:id="@+id/textViewforgotPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center"
android:linksClickable="true"
android:text="@string/link_forgot_password"
android:textAlignment="center"
android:textColor="@color/finger_print_blue"
android:textSize="7pt" />
需要提一下,没有键盘的时候不需要滚动。只有当键盘打开时才需要能够滚动。
你能帮我解决吗?
解决方案
尝试使用windowSoftInputMode
<application
android:hardwareAccelerated="true"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:windowSoftInputMode="adjustPan"
android:theme="@style/AppTheme">
<activity android:name=".Activity.LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
推荐阅读
- python - 我正在尝试将算术运算列表附加到另一个空列表中并返回列表
- javascript - Polymer3 中可以使用哪个表格元素?
- gcloud - GCloud Compute Project-Info Add-Metadata Hangs
- dictionary - 为什么地图上的迭代是随机的?
- java - 我的代码收到 ArrayIndexOutOfBoundsException。这个设置正确吗?
- testing - 是否可以在不使用 NPM 的情况下使用自定义 TestCafé 浏览器提供程序?
- java - 为什么在 Java 8 中删除了 HashMap 的 indexFor 方法
- rest - Spring-boot Web发送回显响应,每隔一个请求
- wordpress - 如何为网站创建 Green lock SSL 证书?
- python - WTF 表单不验证