启动片段并滚动时键盘会打开

时间:2019-10-23 21:57:35

标签: java android xml android-studio

我在片段中有一个滚动视图,当片段打开时,键盘会自动出现并聚焦在布局的第一个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">

1 个答案:

答案 0 :(得分:0)

可聚焦的最高级别视图将被聚焦。如果已聚焦,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">
相关问题