java - 如何修复底部按钮上的软键盘重叠?

标签 java android xml kotlin

这是我的布局。在我的 list 上,它有windowSoftInputMode:"adjustResize|stayVisible它不一定与我的按钮重叠,但它有大约 2 秒的延迟,然后它将停止在我的按钮上重叠。希望任何人都可以帮助我。我应该使用RelativeLayout吗?

<?xml version="1.0" encoding="utf-8"?>
<ScrollView

        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:scrollbars="vertical"
        android:id="@+id/my_scroll_view"
        app:layout_constraintTop_toTopOf="parent">

<androidx.constraintlayout.widget.ConstraintLayout

        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".login.WelcomeScreenActivity">


        <VideoView
                android:id="@+id/video_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity="center" />

            <ImageView
                    android:id="@+id/imageView27"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:src="@drawable/half_black_view" />

        <LinearLayout
                android:id="@+id/linearLayout13"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:gravity="center_horizontal"
                android:orientation="vertical"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintBottom_toTopOf="@+id/login_nxt_btn"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent">

            <androidx.viewpager.widget.ViewPager
                    android:id="@+id/welcome_screen_viewPager"
                    android:layout_width="match_parent"
                    android:layout_height="130dp"></androidx.viewpager.widget.ViewPager>

            <com.google.android.material.tabs.TabLayout
                    android:id="@+id/welcome_screen_indicator"
                    android:layout_width="match_parent"
                    android:layout_height="20dp"
                    android:layout_marginStart="8dp"
                    android:layout_marginLeft="8dp"
                    android:layout_marginTop="8dp"
                    android:layout_marginEnd="8dp"
                    android:layout_marginRight="8dp"
                    app:tabBackground="@drawable/tab_selector"
                    app:tabGravity="center"
                    app:tabIndicatorHeight="0dp"></com.google.android.material.tabs.TabLayout>

            <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="60dp"
                    android:layout_marginStart="16dp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginTop="16dp"
                    android:layout_marginEnd="16dp"
                    android:layout_marginRight="16dp"
                    android:background="@drawable/blur_bg"
                    android:gravity="center_vertical"
                    android:orientation="horizontal"
                    android:padding="8dp">

                <com.hbb20.CountryCodePicker
                        android:id="@+id/ccp"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="16dp"
                        android:layout_marginLeft="16dp"
                        app:ccpDialog_keyboardAutoPopup="false"
                        app:ccp_arrowColor="@color/white"
                        app:ccp_autoDetectCountry="true"
                        app:ccp_contentColor="@color/white"
                        app:ccp_countryPreference="in,us,nz,gb"
                        app:ccp_defaultLanguage="ENGLISH"
                        app:ccp_hintExampleNumber="true"
                        app:ccp_showFlag="false"
                        app:ccp_showNameCode="false"
                        app:ccp_textSize="13sp" />

                <View
                        android:id="@+id/sepratorView"
                        android:layout_width="1dp"
                        android:layout_height="match_parent"
                        android:layout_marginTop="4dp"
                        android:layout_marginBottom="4dp"
                        android:background="@color/app_seperator_color" />

                <EditText
                        android:id="@+id/user_number_edittext"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="16dp"
                        android:layout_marginLeft="16dp"
                        android:background="@android:color/transparent"
                        android:fontFamily="@font/montserrat"
                        android:hint="@string/enter_your_phone_number"
                        android:inputType="phone"
                        android:maxLength="11"
                        android:singleLine="true"
                        android:textColor="@android:color/white"
                        android:textColorHint="@color/white"
                        android:textSize="14sp" />

            </LinearLayout>

            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="16dp"
                    android:layout_marginTop="16dp"
                    android:layout_marginEnd="16dp"
                    android:layout_marginBottom="20dp"
                    android:fontFamily="@font/montserrat_light"
                    android:text="@string/enter_number_recevie_otp"
                    android:textAlignment="center"
                    android:textColor="@color/white"
                    android:textSize="13sp" />



        </LinearLayout>
        <Button
            android:id="@+id/login_nxt_btn"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/rectangle_app_btn"
            android:fontFamily="@font/montserrat_medium"
            android:text="@string/next"
            android:textAllCaps="false"
            android:textColor="@color/white"
            android:textSize="18sp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent" />
        </androidx.constraintlayout.widget.ConstraintLayout>

    </ScrollView>

最佳答案

OnCreate 方法中试试这个。

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

关于java - 如何修复底部按钮上的软键盘重叠?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59590808/

相关文章:

java - 上下文菜单可以打开 ImageView 吗?

xml - 使用 XSLT 对简单 XML 应用 Muenchian 分组

java - 无法打印出来记录猫

android - 缺少 ViewPagerIndicator 依赖项

java - SimpleDateFormat 字符串的正则表达式

java - TFS JAVA SDK14.0.3 - 如何从服务器获取远程文件并进行更改并再次 checkin

java - 使用 JAXB&MOXy 将 JPA 实体转换为 XML 并再次转换回来

xml - 使用 XSLT 检索 XML 文件名

java - OutOfMemoryError 与 NegativeArraySizeException

java - 为 Perl 程序员学习 Java 的书籍推荐