AndroidStudio-TextInput在键盘显示时隐藏字符

问题描述 投票:0回答:2

当我尝试在TextInputEdit中输入字符时,显示键盘时看不到它们。 enter image description here

仅在我的活动中使用最后一个textinputedit时会发生,其他情况下效果很好。当我隐藏键盘时-出现了字符,但是当我尝试再次添加一些字符时,直到键盘隐藏为止,我看不到任何更改。

我的活动xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".Registration"
android:id="@+id/app_bar">

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/regEmailwrapper"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="16dp"
    app:layout_constraintTop_toTopOf="parent"
    tools:layout_editor_absoluteX="0dp">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/regEmail"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:hint="Your Email *"
        android:inputType="textEmailAddress" />
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/regNamewrapper"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="16dp"
    app:layout_constraintTop_toBottomOf="@+id/regEmailwrapper"
    tools:layout_editor_absoluteX="0dp">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/regName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:hint="First name" />
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/regSurnameWrapper"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="16dp"
    app:layout_constraintTop_toBottomOf="@+id/regNamewrapper"
    tools:layout_editor_absoluteX="0dp">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/regSurname"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:hint="Last name" />
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/regPasswordwrapper"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="16dp"
    app:layout_constraintTop_toBottomOf="@+id/regSurnameWrapper"
    tools:layout_editor_absoluteX="0dp">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/regPassword"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:hint="Password *"
        android:inputType="textPassword" />
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/regPassword2wrapper"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="16dp"
    app:layout_constraintTop_toBottomOf="@+id/regPasswordwrapper"
    tools:layout_editor_absoluteX="0dp">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/regPassword2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:hint="Password again *"
        android:inputType="textPassword" />
</com.google.android.material.textfield.TextInputLayout>

<Button
    android:id="@+id/signUp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="16dp"
    android:text="Sign up!"
    app:layout_constraintTop_toBottomOf="@+id/genderDropdown"
    tools:layout_editor_absoluteX="0dp" />

<Spinner
    android:id="@+id/genderDropdown"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="16dp"
    android:spinnerMode="dropdown"
    app:layout_constraintTop_toBottomOf="@+id/regPassword2wrapper"
    tools:layout_editor_absoluteX="0dp" />

</androidx.constraintlayout.widget.ConstraintLayout>

我该如何解决?

java android android-layout android-textinputlayout
2个回答
1
投票

添加此属性:

 android:windowSoftInputMode="adjustPan|adjustResize" 

至您在AndroidManifest.xml中的Activity标签


1
投票

您可以将ConstraintLayout包裹在ScrollView内,以便在看不见TextInput时可以轻松滚动视图>

<ScrollView 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:fillViewport="true">

这应该足够了。我认为无需在Manifest

中添加任何内容
© www.soinside.com 2019 - 2024. All rights reserved.