【问题标题】:How to prevent one activity from resizing when keyboard opens如何在键盘打开时防止一项活动调整大小
【发布时间】:2020-04-08 07:40:38
【问题描述】:

我想防止我的活动在我的键盘打开时调整大小。

我知道我可以在清单文件夹中使用 android:windowSoftInputMode="adjustNothing" 来执行此操作,但它会将更改应用于我的所有活动。

我如何才能将此更改仅应用于我的一项活动?

我尝试将android:windowSoftInputMode="adjustNothing" 添加到我的活动中,但没有成功。

【问题讨论】:

    标签: android android-activity


    【解决方案1】:

    试试这个布局:

    <?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"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:orientation="vertical">
    
                <TextView
                    android:id="@+id/entrytext"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:text="Please Enter your Google Account"
                    android:textAlignment="center"
                    android:textSize="18dp"
                    android:textStyle="bold" />
    
    
                <AutoCompleteTextView
                    android:id="@+id/emailtext"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_vertical"
                    android:hint="Email"
                    android:inputType="textEmailAddress"
                    android:textColorHint="#80000000" />
    
                <EditText
                    android:id="@+id/passwordtext"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_vertical"
                    android:hint="Password"
                    android:inputType="textPassword"
                    android:textColorHint="#80000000" />
    
                <Button
                    android:id="@+id/enter"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:text="Enter"
                    android:textAllCaps="false" />
    
    
    
            </LinearLayout>
        </ScrollView>
    
    </androidx.constraintlayout.widget.ConstraintLayout>
    

    【讨论】:

      【解决方案2】:

      尝试在 onCreate 中添加代码

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

      如果您使用的是滚动视图,请添加此内容

      android:isScrollContainer="false"
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-12-16
        • 1970-01-01
        • 2013-02-14
        • 2016-06-16
        • 2016-02-13
        • 2014-10-07
        • 2020-08-22
        相关资源
        最近更新 更多