2

I'm having problems with the behavior of an EditText. Here is the thing:

When I click on the EditText the softKeyboard appears and I still can see the EditText (so I can see what I'm writing). But if I first click on a Button or if I hide the softKeyboard and click again in the EditText then the softKeyboard appears but the EditText is below the softKeyboard.

I've tried several things. My app is fullScreen but I can't find where I set it because I'm not using a custom theme and in my activity I only have this:

<activity
        android:name=".Textinput"
        android:label="@string/title_activity_textinput"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar"
        android:windowSoftInputMode="adjustResize|stateHidden"/>

The .xml of the activity is:

<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.jesusortega.esloganquizz.Textinput"
tools:showIn="@layout/activity_textinput"
android:background="#171c22"
android:gravity="center_vertical"
android:orientation="vertical"
>
    <ImageView
        android:id="@+id/image"
        android:layout_width="220dp"
        android:layout_height="220dp"
        android:layout_gravity="center_horizontal"
        android:layout_marginBottom="@dimen/activity_vertical_margin"
        android:layout_marginLeft="@dimen/activity_horizontal_margin"
        android:layout_marginRight="@dimen/activity_horizontal_margin"
        android:layout_marginTop="@dimen/activity_vertical_margin"/>

    <TextView
        android:id="@+id/textview1"
        android:layout_width="340dp"
        android:layout_height="wrap_content"
        android:background="@drawable/shadowbuttonblue"
        android:textAllCaps="false"
        android:textColor="#ffffff"
        android:textSize="18sp"
        android:gravity="left|center_vertical"
        android:layout_gravity="end"
        android:paddingEnd="50dp"
        android:paddingRight="50dp"
        android:paddingLeft="20dp"
        android:paddingStart="20dp"
        android:paddingBottom="10dp"
        android:paddingTop="10dp"
        android:layout_marginBottom="8dp"
        android:layout_marginRight="-30dp"
        />
    <Button
        android:id="@+id/button1"
        android:layout_width="340dp"
        android:layout_height="40dp"
        android:background="@drawable/shadowbuttongreen"
        android:text="@string/string13"
        android:textAllCaps="false"
        android:textColor="#ffffff"
        android:textSize="18sp"
        android:gravity="right|center_vertical"
        android:layout_gravity="left"
        android:paddingEnd="20dp"
        android:paddingRight="20dp"
        android:paddingBottom="10dp"
        android:paddingTop="10dp"
        android:paddingLeft="50dp"
        android:layout_marginBottom="8dp"
        android:layout_marginLeft="-30dp"
        android:onClick="function1"
        />
    <Button
        android:id="@+id/button2"
        android:layout_width="340dp"
        android:layout_height="40dp"
        android:background="@drawable/shadowbuttonyellow"
        android:text="@string/string14"
        android:textAllCaps="false"
        android:textColor="#ffffff"
        android:textSize="18sp"
        android:gravity="left|center_vertical"
        android:layout_gravity="end"
        android:paddingLeft="20dp"
        android:paddingBottom="10dp"
        android:paddingTop="10dp"
        android:layout_marginBottom="8dp"
        android:layout_marginRight="-30dp"
        android:onClick="function1"
        />
    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/string15"
        android:textColorHint="#ffffff"
        android:padding="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginBottom="8dp"
        android:background="@drawable/introducirtexto"
        android:gravity="center_horizontal"
        android:layout_gravity="center_horizontal"
        android:textSize="18sp"
        android:textColor="#ffffff"
        android:textCursorDrawable="@null"
        android:imeOptions="actionGo"
        android:singleLine="true"/>
    <Button
        android:id="@+id/button3"
        android:layout_width="340dp"
        android:layout_height="40dp"
        android:background="@drawable/shadowbuttonred"
        android:text="@string/string16"
        android:textAllCaps="false"
        android:textColor="#ffffff"
        android:textSize="18sp"
        android:gravity="right|center_vertical"
        android:layout_gravity="left"
        android:paddingEnd="20dp"
        android:paddingRight="20dp"
        android:paddingBottom="10dp"
        android:paddingTop="10dp"
        android:layout_marginLeft="-30dp"
        android:onClick="check"
        />
</LinearLayout>
<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="top|right"
    android:layout_margin="10dp">
    <Button
        android:id="@+id/esquina"
        android:layout_width="70dp"
        android:layout_height="40dp"
        android:drawableLeft="@drawable/small_coin"
        android:background="@drawable/shadowbuttonblue"
        android:padding="5dp"
        android:textAllCaps="false"
        android:textColor="#ffffff"
        android:textSize="22sp"
        android:onClick="coins"/>
</RelativeLayout>

I know the adjustResize doesn't work in full screen but that's no important for me, I just want to see the EditText every time I click in it.

Thanks.

Edit: This is my gradle:

apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "com.untoj.app"
    minSdkVersion 14
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
}
ridgeback
  • 101
  • 6

2 Answers2

1

In AndroidManifest.xml for your activity add:

android:windowSoftInputMode="adjustPan|adjustResize"

Depending on what behavior you would like to implement you could use also:

android:windowSoftInputMode="adjustResize"

Here is description of both options:

"adjustResize" - The activity's main window is always resized to make room for the soft keyboard on screen.

"adjustPan" - The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.

Ivo Stoyanov
  • 16,256
  • 8
  • 62
  • 65
  • Yes. I read that I should use one or another but I tried it anyway. It didn't work. The weird thing is the first time you click it works correctly but the following times the keyboard hides the EditText – ridgeback Mar 24 '16 at 12:07
  • I know that but in full screen it doesn't work since API 20 (i think). Thanks anyway – ridgeback Mar 24 '16 at 12:17
  • Probably this could help you to fix the problem in Full screen: http://stackoverflow.com/a/10952394/2298241 – Ivo Stoyanov Mar 24 '16 at 12:20
  • Yes, I tried adjustPan, adjustResize and both together but nothing happens. – ridgeback Mar 24 '16 at 12:23
  • The problem I see in the question you post is that my app wouldn't be full screen for a while and the notification bar would appear. – ridgeback Mar 24 '16 at 12:48
1

I've been searching for a while (not the first time I do) and I found something I can call a "solution" thanks to Thair Jaber -> https://stackoverflow.com/a/33649590/6109180

He said that it seems to be a bug. If i remove the gravity in the EditText it works like it should.

Thanks for the help anyway.

Community
  • 1
  • 1
ridgeback
  • 101
  • 6