0

I'm trying to creat a simple activity with an EditText at the top and a Button at the bottom. This last should be above the keyboard when it is open, but I don't get any good result (it stay on the bottom, hidden by the keyboard).

I found lot of subjects on this, so I tryed :

  • android:windowSoftInputMode="adjustResize" (also with adjustPan)
  • android:fitsSystemWindows="true"
  • a scrollview

but that do not helped.

there is my 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>

Thanks for your help.

Sanders248
  • 51
  • 1
  • 7

2 Answers2

3

Use the layout below.

<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>

And manifest entry of your activity should be.

 <activity
        android:name=".MainActivity"
        android:theme="@style/AppTheme.NoActionBar"
        android:windowSoftInputMode="adjustResize">
    </activity>
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
ADM
  • 20,406
  • 11
  • 52
  • 83
  • **`android:orientation="vertical"`** not required read here https://developer.android.com/guide/topics/ui/layout/relative.html – AskNilesh Dec 11 '17 at 11:02
  • Thanks a lot, that work with: android:theme="@style/Theme.AppCompat.NoActionBar" – Sanders248 Dec 11 '17 at 11:08
  • 1
    @Nilu change Linearlayout to realtive so by mistake it left there. Thx for pointing out . – ADM Dec 11 '17 at 11:12
  • Finally, that doesn't work exactly as I want. The button is now at the good place, but I'have not anymore the fullscreen mode (without the android bar). And when I add the fullscreen mode, the button, disappears behind the keyboard.. – Sanders248 Dec 11 '17 at 11:37
  • fullscreen mode does not resize. – ADM Dec 11 '17 at 11:45
  • with this: android:windowFullscreen="true" and this: android:windowNoTitle="true" – Sanders248 Dec 11 '17 at 11:49
  • Yeah have a look into these SO thread [Thread1](https://stackoverflow.com/questions/7417123/android-how-to-adjust-layout-in-full-screen-mode-when-softkeyboard-is-visible), [Thread2](https://stackoverflow.com/questions/21092888/windowsoftinputmode-adjustresize-not-working-with-translucent-action-navbar). Good luck thx – ADM Dec 11 '17 at 11:51
  • thanks, that works now with the solution of this topic: https://stackoverflow.com/questions/7417123/android-how-to-adjust-layout-in-full-screen-mode-when-softkeyboard-is-visible/19494006#19494006 – Sanders248 Dec 11 '17 at 13:19
  • Thx . happy coding . – ADM Dec 11 '17 at 13:25
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>

Use this layout will solve your issue.

Rishabh Mahatha
  • 1,251
  • 9
  • 19