Gal Rom
Gal Rom

Reputation: 6461

EditText inside a fragment is Hidden when soft keyboard opens

My Activity contains two fragments , at the bottom a control bar and above it this layout with two EditText:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/invested_grey_color" >

<RelativeLayout
    android:id="@+id/relativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="5dp"
    android:background="@color/transperent_black" >

    <com.threefishmedia.sportzone.views.TextViewCustomFont
        android:id="@+id/choose_a_set_LeagueName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/view_tournament_rules"
        android:textColor="@color/white"
        android:textSize="20sp" />

    <ImageView
        android:id="@+id/choose_a_set_view_tournamnet_rules_iv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="10dp"
        android:layout_toLeftOf="@+id/choose_a_set_LeagueName"
        android:clickable="true"
        android:src="@drawable/question" />
</RelativeLayout>

<RelativeLayout
    android:id="@+id/Choose_a_set_rl"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/relativeLayout1"
    android:layout_marginTop="15dp"
    android:background="@color/transperent_sportzone_green" >

    <com.threefishmedia.sportzone.views.TextViewCustomFont
        android:id="@+id/choose_a_set_stage_tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_marginBottom="20dp"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="20dp"
        android:text="@string/choose_a_set"
        android:textColor="@color/sportzone_green"
        android:textSize="35sp" />

    <ImageView
        android:id="@+id/choose_a_set_vi_sign_iv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_marginRight="20dp"
        android:src="@drawable/ic_launcher" />
</RelativeLayout>

<RelativeLayout
    android:id="@+id/make_it_your_own"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/Choose_a_set_rl"
    android:layout_marginTop="1dp"
    android:background="@color/transperent_sportzone_green" >

    <com.threefishmedia.sportzone.views.TextViewCustomFont
        android:id="@+id/make_it_your_own_tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_marginBottom="20dp"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="20dp"
        android:text="@string/make_it_your_own"
        android:textColor="@color/sportzone_green"
        android:textSize="35sp" />
</RelativeLayout>

<LinearLayout
    android:id="@+id/add_tournament_name_ll"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/edit_text_wraper"
    android:layout_marginTop="14dp"
    android:background="@color/add_tournament_red_color"
    android:visibility="invisible" >

    <com.threefishmedia.sportzone.views.TextViewCustomFont
        android:id="@+id/information_to_user_tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="3dp"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="3dp"
        android:text="@string/add_tournamnet_name"
        android:textColor="@color/white"
        android:textSize="20sp" />
</LinearLayout>

<RelativeLayout
    android:id="@+id/tournamnet_make_it_your_own_next_btn"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_marginTop="5dp"
    android:layout_below="@+id/add_tournament_name_ll"
    android:background="@color/transperent_black"
    android:clickable="true"
    android:enabled="false" >

    <com.threefishmedia.sportzone.views.TextViewCustomFont
        android:id="@+id/make_iyt_your_own_next_tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:layout_marginBottom="30dp"
        android:layout_marginTop="30dp"
        android:text="@string/next"
        android:textColor="@color/disables_btn_text_color"
        android:textSize="@dimen/next_btn_font" />
</RelativeLayout>

<RelativeLayout
    android:id="@+id/invite_friends_rl"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="5dp"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/tournamnet_make_it_your_own_next_btn"
    android:background="@color/transperent_sportzone_green" >

    <com.threefishmedia.sportzone.views.TextViewCustomFont
        android:id="@+id/invites_friends_tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_marginBottom="20dp"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="20dp"
        android:text="@string/invite_your_friends"
        android:textColor="@color/sportzone_green"
        android:textSize="35sp" />
</RelativeLayout>

<RelativeLayout
    android:id="@+id/edit_text_wraper"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/make_it_your_own" >

    <com.threefishmedia.sportzone.views.TextViewCustomFont
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="15dp"
        android:layout_marginTop="20dp"
        android:text="@string/tournament_name"
        android:textColor="@color/white"
        android:textSize="30sp" />

    <EditText
        android:id="@+id/tournament_name_et"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignLeft="@+id/textView1"
        android:layout_below="@+id/textView1"
        android:layout_marginRight="20dp"
        android:background="@drawable/rounded_et"
        android:ems="10"
        android:inputType="text"
        android:maxLength="30"
        android:paddingLeft="20dp"
        android:textSize="30sp" >

        <requestFocus />
    </EditText>

    <com.threefishmedia.sportzone.views.TextViewCustomFont
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/tournament_name_et"
        android:layout_below="@+id/tournament_name_et"
        android:layout_marginTop="26dp"
        android:text="@string/jeckpot"
        android:textColor="@color/white"
        android:textSize="30sp" />

    <EditText
        android:id="@+id/jeckpot_amont_et"
        android:layout_width="220dp"
        android:layout_height="50dp"
        android:layout_alignLeft="@+id/textView2"
        android:layout_below="@+id/textView2"
        android:background="@drawable/rounded_et"
        android:ems="10"
        android:inputType="number"
        android:maxLength="9"
        android:paddingLeft="20dp"
        android:textSize="35sp" />

    <ImageView
        android:id="@+id/tournamentt_type_instructions_iv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/jeckpot_amont_et"
        android:layout_alignRight="@+id/tournament_name_et"
        android:clickable="true"
        android:src="@drawable/question" />

    <com.threefishmedia.sportzone.views.TextViewCustomFont
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/tournamentt_type_instructions_iv"
        android:layout_toRightOf="@+id/textView1"
        android:text="@string/tournament_type"
        android:textColor="@color/white"
        android:textSize="30sp" />

    <Switch
        android:id="@+id/basic_expert_switcher"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/jeckpot_amont_et"
        android:layout_alignBottom="@+id/jeckpot_amont_et"
        android:layout_toRightOf="@+id/textView1"
        android:textOff="@string/basic"
        android:textOn="@string/expert"
        android:thumb="@drawable/thumb_selector"
        android:track="@drawable/switch_bg" />

</RelativeLayout>

the problem is when the uses taps on the second EditText the keyboard hides it and the user can't see what he is typing. i worked on it for to long... i have added

android:windowSoftInputMode="adjustResize"

and adjustpan in Manifest file , none of them helped.

any ideas?

Upvotes: 6

Views: 4491

Answers (4)

Mike Schvedov
Mike Schvedov

Reputation: 156

According to the documentation:

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

So inside a fragment you should use adjustPan in the manifest:

<activity
    ...
    android:windowSoftInputMode="adjustPan"/>

Notice, that the keyboard will still hide the edittext, if the edittext is not currently focused (you are not typing inside of it.)

Upvotes: 0

hmuss
hmuss

Reputation: 301

I was having a similar problem and adding this to the manifest worked for me.

<activity
    ...
    android:windowSoftInputMode="adjustPan"/>

Upvotes: 0

Ram
Ram

Reputation: 1428

you can also put this line on manifest

   android:windowSoftInputMode="adjustResize|stateHidden"

Upvotes: 0

Sreedhu Madhu
Sreedhu Madhu

Reputation: 2470

Put this line inside oncreate,

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

Upvotes: 15

Related Questions