繁体   English   中英

如何在键盘上方移动按钮?

[英]How to move a button above the keyboard?

之前已经问过这个问题,但我找不到适合我的好答案。

这是我的XML代码(更新):

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Account Name"
        android:textSize="32dp"
        android:layout_marginTop="15dp"
        android:layout_marginLeft="15dp"
        android:id="@+id/textView" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:id="@+id/accountName"
        android:background="@drawable/edit_text_background"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:padding="10dp"
        android:backgroundTint="@color/abc_secondary_text_material_light" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Account Balance"
        android:textSize="32dp"
        android:layout_marginTop="15dp"
        android:layout_marginLeft="15dp"/>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:inputType="numberDecimal"
        android:id="@+id/accountBalance"
        android:background="@drawable/edit_text_background"
        android:layout_marginRight="15dp"
        android:layout_marginLeft="15dp"
        android:padding="10dp"
        android:backgroundTint="@color/abc_secondary_text_material_light"
        android:text="£"
        />


    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="20dp"
        android:text="New Button"
        android:id="@+id/button"
        android:layout_gravity="center_horizontal"
        android:layout_alignParentBottom="true"
        />

</RelativeLayout>

我尝试过使用android:windowSoftInputMode="adjustPan|adjustResize"但它没有用。

我觉得我对XML代码的布局做错了......它看起来像这样,我想按键在键盘出现时向上移动:

在此输入图像描述

尝试在父级别使用ScrollView

<ScrollView
            android:id="@+id/login_form"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            >

在AndroidManifest.xml中

android:windowSoftInputMode="stateVisible|adjustResize"

在style.xml文件中将您的活动样式设置为

<item name="android:windowActionBarOverlay">true</item>

确保您没有使用全屏活动。

我长期与同样的事情挣扎。 对我有用的解决方案是

将以下行添加到活动清单中。

android:windowSoftInputMode="stateHidden"

我请求在scrollview中保持布局,除了你想用键盘移动的视图(在这个问题情况下的按钮)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM