出现软键盘时向上移动布局

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

在给定的图片中,您可以看到每当我尝试在编辑文本中输入内容时,软键盘会覆盖提交按钮,这真的很令人沮丧。 所以经过一些研究我发现它可以通过使用来解决 -

android:windowSoftInputMode="stateVisible|adjustResize"
在该活动下的 android menifest.xml 文件中。 但它对我不起作用。谁能帮我解决这个问题。 before keyboard appears after keyboard appears

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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical"
    android:background="@drawable/background"
    android:gravity="center">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Quiz App!"
        android:textColor="@color/white"
        android:gravity="center"
        android:textStyle="bold"
        android:textSize="24sp"
        android:layout_marginBottom="30dp"/>
    <com.google.android.material.card.MaterialCardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="20dp"
        android:layout_marginEnd="20dp"
        android:background="@color/white"
        app:cardCornerRadius="28dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_margin="16dp">
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="WELCOME!"
                android:textStyle="bold"
                android:textSize="30sp"
                android:gravity="center"
                android:textColor="@color/black"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Please enter your name"
                android:layout_marginTop="16dp"
                android:textSize="16sp"
                android:gravity="center"
                android:textColor="@color/black"/>

            <com.google.android.material.textfield.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
                <androidx.appcompat.widget.AppCompatEditText
                    android:id="@+id/et_name"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Name"
                    android:inputType="textCapWords"
                    android:textColor="#363A43"
                    android:textColorHint="#7A8089"/>

            </com.google.android.material.textfield.TextInputLayout>
            <Button
                android:id="@+id/btnStart"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Start"
                android:layout_marginTop="16dp"
                android:textColor="@color/white"/>
        </LinearLayout>

    </com.google.android.material.card.MaterialCardView>

</LinearLayout>

我尝试实施

android:windowSoftInputMode="stateVisible|adjustResize"
。但它没有用。 我想知道为什么它不起作用,以及是否有其他方法可以解决这个问题。

android xml android-layout android-softkeyboard
© www.soinside.com 2019 - 2024. All rights reserved.