键盘上方的android按钮

时间:2017-12-11 10:41:39

标签: android button keyboard position

我正在尝试使用顶部的EditText和底部的Button创建一个简单的活动。当它打开时,这最后应该在键盘上方,但我没有得到任何好结果(它保持在底部,被键盘隐藏)。

我发现了很多主题,所以我尝试了:

  • android:windowSoftInputMode =“adjustResize”(也使用adjustPan)
  • 机器人:fitsSystemWindows = “真”
  • 一个scrollview

但这没有帮助。

有我的xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/search_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    android:fitsSystemWindows="true">

    <fr.bowo.app.widget.page.EditTextPreIme
        android:id="@+id/edit_text_dialog"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:layout_marginTop="100dp"
        android:gravity="center"
        android:hint="Rechercher par mot..."
        android:imeOptions="actionSearch"
        android:inputType="textAutoCorrect"
        android:lines="1"
        android:maxLines="1"
        android:textAppearance="@style/BoldFont"
        android:textColor="@color/black"
        android:textSize="@dimen/title" />

    <Button
        android:id="@+id/search_image"
        android:layout_width="@dimen/icon_size"
        android:layout_height="@dimen/icon_size"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:layout_marginBottom="@dimen/border_small"
        android:layout_marginEnd="@dimen/border_small" />
</RelativeLayout>

感谢您的帮助。

2 个答案:

答案 0 :(得分:3)

使用下面的布局。

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">


<EditText
    android:id="@+id/et"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<Button
    android:id="@+id/search_image"
    android:layout_width="100dp"
    android:text="Hit"
    android:layout_centerHorizontal="true"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="20dp"

    />
</RelativeLayout>

你的活动的明确录入应该是。

 <activity
        android:name=".MainActivity"
        android:theme="@style/AppTheme.NoActionBar"
        android:windowSoftInputMode="adjustResize">
    </activity>

答案 1 :(得分:0)

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:fillViewport="true"
    android:layout_height="match_parent">

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/search_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ffffff"
        android:fitsSystemWindows="true">

        <fr.bowo.app.widget.page.EditTextPreIme
            android:id="@+id/edit_text_dialog"
            android:layout_width="match_parent"
            android:layout_height="80dp"
            android:layout_marginTop="100dp"
            android:gravity="center"
            android:hint="Rechercher par mot..."
            android:imeOptions="actionSearch"
            android:inputType="textAutoCorrect"
            android:lines="1"
            android:maxLines="1"
            android:textAppearance="@style/BoldFont"
            android:textColor="@color/black"
            android:textSize="@dimen/title" />

        <Button
            android:id="@+id/search_image"
            android:layout_width="@dimen/icon_size"
            android:layout_height="@dimen/icon_size"
            android:layout_alignParentBottom="true"
            android:layout_alignParentEnd="true"
            android:layout_marginBottom="@dimen/border_small"
            android:layout_marginEnd="@dimen/border_small" />
    </RelativeLayout>
</ScrollView>

使用此布局将解决您的问题。