我在片段中有一个滚动视图,当片段打开时,键盘会自动出现并聚焦在布局的第一个edittext上,并且屏幕滚动并且打开键盘时我看不到所有字段。
因此,如何防止片段开始时出现键盘,以及如何在打开键盘的情况下查看滚动视图中的所有字段?
谢谢
那是XML的一部分
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/personalDataLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
tools:context=".presentation.fragments.PersonalDataFragment">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
最佳答案
可聚焦的最高级别视图将被聚焦。如果已聚焦,EditTexts会拉起键盘。但是,如果将以下内容添加到父视图(RelativeLayout,LinearLayout等)中,则不会自动打开键盘
android:focusable="true"
android:focusableInTouchMode="true"
例:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_height="match_parent">