1

I have an activity with a couple of editText in the top of the activity and two buttons that i have in a footer.

When I press one of the edit text the keyboard is shows up and the footer adjustResize. This is the behaviour that I want to have.

My problem is that when I try to press one of this buttons (when the keyboard is visible) the keyboard is hidden and the action to press the button is not working.

My question is, how can I keep the footer working when the keyboard is visible in the activity.

My activity in the manifest:

 <activity
        android:name=".activity.InitSessionActivity"
        android:configChanges="orientation"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustResize" />

I've created my activity according to the solution of this answer: How to adjust layout when soft keyboard appears

My activity xml:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:layout_width="match_parent"
    android:layout_height="match_parent"
    style="@style/screen"
    android:fillViewport="true"
    android:background="@color/colorPrimary"
    android:layout_alignParentBottom="true"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        style="@style/screen"
        android:id="@+id/ly_general"
        android:fitsSystemWindows="true">

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            style="@style/inputTextLayout"
            android:layout_marginTop="172dp"
            app:hintTextAppearance="@style/edittextWithTextInputLayout"
            android:layout_centerHorizontal="true"
            android:id="@+id/textInputLayout">

        </android.support.design.widget.TextInputLayout>


        <include layout="@layout/footer" />

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            style="@style/inputTextLayout"
            app:hintTextAppearance="@style/edittextWithTextInputLayout"
            android:id="@+id/textInputLayoutEmail"
            android:layout_below="@+id/text_init_session"
            android:layout_marginTop="@dimen/padding_10">

            <EditText
                android:id="@+id/login_ed_email"
                android:layout_width="314dp"
                android:layout_height="wrap_content"
                android:hint="@string/login_hint_email"
                android:drawablePadding="5dp"
                android:inputType="textEmailAddress"
                android:textColorHint="@color/white3"
                style="@style/edittextWithTextInputLayout"
                android:transitionName="@string/email"
                android:nextFocusDown="@+id/login_ed_password"
                android:layout_marginTop="9dp"
                android:layout_below="@+id/text_init_session"
                android:layout_alignParentRight="true"
                android:layout_alignParentEnd="true"
                android:backgroundTint="@color/secundary_foreground" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            style="@style/inputTextLayout"
            app:hintTextAppearance="@style/edittextWithTextInputLayout"
            android:id="@+id/textInputLayout2"
            android:layout_marginTop="16dp"
            android:layout_below="@+id/textInputLayoutEmail">

            <EditText
                android:id="@+id/login_ed_password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Contraseña"
                android:textColorHint="@color/colorPrimary"
                style="@style/edittextWithTextInputLayout"
                android:transitionName="@string/password"
                android:drawableLeft="@drawable/login_ico_password"
                android:drawablePadding="5dp"
                android:nextFocusDown="@+id/login_btn_enter"
                android:nextFocusUp="@+id/login_ed_email"
                android:inputType="textPassword"
                android:backgroundTint="@color/secundary_foreground" />
        </android.support.design.widget.TextInputLayout>

        <TextView
            android:id="@+id/login_tx_forgot"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:textColor="@color/secundary_foreground"
            android:padding="@dimen/margin_13"
            android:text="@string/login_forgot_password"
            android:layout_below="@+id/textInputLayout2"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginLeft="@dimen/padding_16"/>

        <TextView
            android:text="@string/login_title_init_session"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="@color/white"
            android:padding="10dp"
            android:textSize="@dimen/text_size_22"
            android:id="@+id/text_init_session"
            android:layout_marginTop="17dp"
            android:layout_marginLeft="@dimen/padding_13"
            android:layout_below="@+id/image"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />

        <ImageView
            android:id="@+id/image"
            android:layout_width="134dp"
            android:layout_height="45dp"
            android:src="@drawable/logo_loycus_new"
            android:layout_alignParentTop="true"
            android:layout_alignLeft="@+id/textInputLayoutEmail"
            android:layout_alignStart="@+id/textInputLayoutEmail" />

    </RelativeLayout>
</ScrollView>

Foter:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/footer"
    android:layout_width="match_parent"
    android:layout_height="70dp"
    android:layout_alignParentBottom="true"
    android:gravity="center"
    android:background="@color/colorPrimary">

    <View
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:background="@color/backgroundScreens"
        android:id="@+id/view"/>

    <Button
        android:text="@string/volver"
        android:textAllCaps="false"
        android:layout_width="@dimen/button_folder_widht"
        android:layout_height="@dimen/button_folder_height"
        android:id="@+id/buttonComeBack"
        android:background="@drawable/btn_selecto_come_back"
        android:textColor="@color/white"
        android:layout_marginLeft="@dimen/margin_16"
        android:layout_marginTop="@dimen/padding_10"/>

    <Button
        android:layout_marginTop="@dimen/padding_10"
        android:text="@string/enter"
        android:textAllCaps="false"
        android:layout_width="@dimen/button_folder_widht"
        android:layout_height="@dimen/button_folder_height"
        android:background="@drawable/btn_selector_green"
        android:textColor="@color/colorPrimary"
        android:id="@+id/login_loycus"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_marginRight="@dimen/margin_16"/>

</RelativeLayout>
Community
  • 1
  • 1
S.P.
  • 2,274
  • 4
  • 26
  • 57

2 Answers2

1

Edit your footer as:-

<include layout="@layout/footer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />

Remove this from ScrollView

android:layout_alignParentBottom="true" 

Remove this from relative layout having id ly_general

android:fitsSystemWindows="true" 

Add this to scrollview

android:fitsSystemWindows="true" 

EDIT:-

If you don't want to align your footer to bottom, then remove this line

android:layout_alignParentBottom="true"

and adjust it wherever you want to place it on your UI.

Nainal
  • 1,728
  • 14
  • 27
  • Hi Nainal. I've tried your changes but the effect is the same. The footer is show with the keyboard but when I try to press the button, the keyboard is hide and the press button doesn't work. At this moment, the button come back at the down of the activity and, now I can press and work, but this is not the behaviour that I want. I need to be able to press the button when the keyboard is showed – S.P. Dec 27 '16 at 10:38
  • i am not sure it will work or not ,try this in your onclick :- – Nainal Dec 27 '16 at 10:51
  • if(view.hasFocus()){ InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); } – Nainal Dec 27 '16 at 10:52
  • which action you are taking in your button click – Nainal Dec 27 '16 at 10:59
  • Something simple, go to another activity. Problem is that when I press button, keyboard desappear, button go down in the activity and don't do nothing – S.P. Dec 27 '16 at 11:09
  • but earlier you said that now you can press and it worked – Nainal Dec 27 '16 at 11:14
  • Sorry, maybe I've explained me bad. The button work when the keyboard is hide, but I want that work when the keyboard is show, too, and the footer is above of the keyboard. You know what I mean? – S.P. Dec 27 '16 at 11:24
0

I just tried out your xml with a footer i wrote

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="40dp"
              android:layout_alignParentBottom="true"
                android:background="@android:color/black">

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="button 1"/>

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="button 2"/>

</LinearLayout>

and everything seems to be working fine. can you maybe explain the problem a bit more? or post your code/footer?

Yuxal
  • 445
  • 4
  • 14
  • Hi Yuxal. I've updated my code with my footer xml. The footer is working fine and is showed with the keyboard. My problem is that if I try to press the button, the keyboard is hide and the press button is not working. That i want to do is can press the button footer while the keyboard is showed. You know what I mean?? – S.P. Dec 27 '16 at 10:36
  • Have you implemented onclicklistener on button? – Nainal Dec 27 '16 at 10:38
  • Yes, because when the keyboard is not showed I can press the button and works – S.P. Dec 27 '16 at 10:39
  • @S.P. Can you post a screenshot of the issue? it's hard to understand what's wrong – Yuxal Dec 27 '16 at 11:28