如何使按钮在软键盘弹出时保持在底部

14

我在屏幕底部有一个按钮,我希望它即使软键盘弹出时也能保持在下方,但目前它会随着软键盘一起弹出。我试过将按钮对齐到底部,但没有成功。

这是代码(按钮在id/activity_form_button_frame内):

<RelativeLayout>
     <RelativeLayout
        android:id="@+id/activity_form_button_frame"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true">
    <ImageButton
        android:id="@+id/activity_form_next_button"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@android:color/black"
        android:src="@drawable/next_btn_drawable"
        android:scaleType="fitCenter"
        android:padding="5dp"
        />
    <Button
        android:id="@+id/activity_form_sumbit_button"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@android:color/black"
        android:text="SUBMIT"
        android:textColor="@color/buttonBlue"
        android:visibility="gone"
        android:padding="15dp"
        style="@android:style/TextAppearance.Large"/>
    </RelativeLayout>

    <FrameLayout
        android:id="@+id/activity_form_fragmentcontainer"
        android:layout_below="@id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/activity_form_button_frame"/>

    </RelativeLayout>

请检查下面的答案。 - Jay Rathod
10个回答

20
AndroidManifest.xml文件中,为您的活动设置android:windowSoftInputMode="adjustPan"

像这样。

<activity
    android:windowSoftInputMode="adjustPan">

或者:

<activity
    android:windowSoftInputMode="adjustPan|adjustResize">

你也可以通过编程实现此操作。

onCreate() 方法中使用以下代码:

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

请查看此处了解详情。


1
有了代码:android:windowSoftInputMode="adjustPan",我们如何调整小部件与键盘之间的距离?例如,在我的情况下,我希望一个按钮在键盘上方但在EditText下方,以便用户可以输入文本然后单击该按钮。我该如何实现这一点? - Vaggelis Manousakis

3

尝试这个...

<activity
android:windowSoftInputMode="adjustPan">

3

试试这个

<activity
android:windowSoftInputMode="adjustPan">

或者在代码中。
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

1
尝试在您的活动属性android:windowSoftInputMode中添加清单。 将其设置为adjustResize或adjustPan。其中一个将起作用。

0

在你的AndroidManifest文件和activity中添加属性,如下所示:

android:windowSoftInputMode="adjustResize"

将光标直接移到上面的按钮并打开键盘。


0
在我的情况下,我正在使用<item name="android:windowFullscreen">true</item>在我的主题中。这会导致问题,因此我同时使用了android:windowSoftInputMode="adjustResize"

0

在您的清单文件中,在活动标签下添加此行。

android:windowSoftInputMode="stateHidden|adjustResize"

例如,
<activity
    android:name="packagename.ClassName"
    android:label="@string/app_name"
    android:windowSoftInputMode="stateHidden|adjustResize" >
</activity>

然后你就可以开始了。


0
在您的清单文件中,活动标签下添加以下行。
android:windowSoftInputMode="adjustPan|adjustResize"

0
在你的AndroidManifest.xml中尝试使用这段代码:
<activity
            android:name="com.facebook.FacebookActivity"
            android:windowSoftInputMode="adjustPan|adjustResize"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.Translucent.NoTitleBar" />

-4

你可以使用 android:layout_alignParentBottom="true" 实现这个功能。


我在RelativeLayout中尝试了for循环,但没有结果(请参见代码) - bvk256
@bvk256 你需要为按钮做这个。 - UserSharma
请将您的RelativeLayout的高度设置为match_parent。 - UserSharma

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接