当前位置: 首页 > 知识库问答 >
问题:

当软键盘出现时,保持工具栏位置固定在布局中,软键盘位于编辑文本下面

姚实
2023-03-14

这是我的简单观点:

<?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/activity_main3"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.utkarsh.test.Main3Activity">

    <EditText
        android:layout_marginTop="180dip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:hint="edit text1" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:hint="edit text2" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:hint="edit text3" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:hint="edit text4" />


</LinearLayout>

我想要2个条件:1]一旦我开始输入我的编辑文本,键盘应该在下面的特定编辑文本2]标题栏应该保持固定在那个位置。

我在manifest中使用了Android:WindowsoftinPutmode=“adjustpan”来实现第一个条件,但同时没有实现第二个条件。其次,使用Android:windowsoftinputmode=“adjustrestsize”可以实现2个条件,但1个条件没有实现。同时使用Android:WindowsoftinPutmode=“adjustresizeAdjustPan”可以执行与调整和调整大小相同的操作。我已经尝试了所有的答案,比如Android:WindowsoftinPutmode=“AdjustNothing”,但没有任何帮助

我怎样才能同时达到这两个条件??

共有1个答案

胡俊美
2023-03-14

如果我理解您的话,请尝试使用scrollview。示例:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="pl.com.qubuss.test.RegisterActivity">
<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/nameET"
    android:layout_marginTop="20dp"
    android:inputType="textPersonName"
    android:hint="@string/nameTextHint"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:width="200dp" />

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/surnameET"
    android:layout_below="@+id/nameET"
    android:layout_alignLeft="@+id/nameET"
    android:layout_alignStart="@+id/nameET"
    android:layout_marginTop="20dp"
    android:width="200dp"
    android:hint="@string/surnameTextHint" />

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="textEmailAddress"
    android:ems="10"
    android:id="@+id/emailET"
    android:hint="@string/emailTextHint"
    android:width="200dp"
    android:layout_below="@+id/surnameET"
    android:layout_alignLeft="@+id/surnameET"
    android:layout_alignStart="@+id/surnameET"
    android:layout_marginTop="20dp" />

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/username_registerET"
    android:layout_below="@+id/emailET"
    android:layout_alignLeft="@+id/emailET"
    android:layout_alignStart="@+id/emailET"
    android:layout_marginTop="20dp"
    android:width="200dp"
    android:hint="@string/usernameTextHint" />

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="textPassword"
    android:ems="10"
    android:id="@+id/password_registerET"
    android:layout_below="@+id/username_registerET"
    android:layout_alignLeft="@+id/username_registerET"
    android:layout_alignStart="@+id/username_registerET"
    android:layout_marginTop="20dp"
    android:hint="@string/passwordTextHint" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/registerButton"
    android:id="@+id/registerButton"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="23dp"
    android:layout_below="@+id/conPasswor_registerET"/>

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="textPassword"
    android:ems="10"
    android:id="@+id/conPasswor_registerET"
    android:layout_marginTop="20dp"
    android:layout_below="@+id/password_registerET"
    android:layout_alignLeft="@+id/password_registerET"
    android:layout_alignStart="@+id/password_registerET"
    android:hint="@string/conPasswordTextHint" />
</RelativeLayout>
</ScrollView>
 类似资料:
  • 见下面的图片。当我点击编辑文本时,我的整个布局被推到顶部。结果应该是工具栏 图像 1 图片2 我的布局如下所示: 这是我的清单。xml文件: 我尝试过已经尝试过“调整大小”,但问题是我在底部的线性布局隐藏在键盘下。 那么我该怎么做呢?

  • 我有一个片段,其中包含一个ViewPager2的2个fragemnt。在第二个子片段中,我有一个回收器视图,其视图保持器包含 TextView 和 EditText。 在模拟器中,当我点击编辑视图时,软键盘一直关闭。 在真实设备(索尼xperia XA)中,软键盘没有关闭,但它总是关注第一个编辑文本,无论我是否在另一个编辑文本中单击 我曾尝试使用android:WindowsOfInputMode

  • 我想在软键盘激活时调整版面的大小,如下所示: 前后: 在SO: 在显示软键盘时如何保持所有字段和文本可见 安卓软键盘出现时破坏布局 软键盘打开时调整布局 但问题和答案是相当模糊的,这里的问题更清楚地描述了我想要什么。 要求: 它应适用于任何屏幕大小的电话。 注意到“facebook”和“注册facebook”处的边距/填充空间前后发生了变化。 不涉及滚动视图。

  • 这是一个布局: 我希望在触摸EditText并显示软键盘时,蓝色条保持不变。一、 我希望它的大小和位置得到保留。我在AndroidManifest中尝试了我的活动参数android:WindowsofInputMode的所有四个可能值。我的蓝条总是在软键盘上移动或收缩: android:WindowsofInputMode=“adjustUnspecified”或默认设置: android:win

  • 我有一个编辑文本,我想自己处理输入,所以我不想在我点击它时(或者当选择改变、焦点改变、长时间点击等)软键盘出现。但是,我仍然希望能够选择文本、更改光标位置、复制/过去等。 我曾尝试将Android系统:windowSoftInputMode=“stateAllwayshidden”放入清单中,但似乎效果不大。我还尝试添加以下内容 这会禁用键盘,但也会阻止光标工作。 目前,我基本上是在尝试为键盘可能