2

My question is the following, how do I go about removing a RelativeLayout containing buttons every time the user calls up the soft keyboard to type on an editText on the same layout. As you can see on my images below, the buttons within the red box need to disappear every time the user is inputing information and reappear after the keyboard has been called off.

FYI - The RelativeLayout needs to be fixed at the bottom when the keyboard is not in view so "layout_alignParentBottom='false' is not a solution for me. I think this most likely needs to be done programatically.

Any suggestions on how to tackle this problem would be highly appreciated.

    <RelativeLayout
    android:id="@+id/footer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_margin="@dimen/activity_margin_zero"
    android:background="@color/background"
    android:minHeight="48dp"
    android:padding="@dimen/activity_margin_zero">

Here is what Google Android Developer site describes as "Persistent Footer Button"

Persistent Footer Button - Android Material Design

This is what I have but the so called "Persistent Footer Button" should disappear when the keyboard is on screen.

Before inputing value on an editText

Buttons should be behind keyboard when it shows or disappear so that the user can input information with more screen real state.

Inputing a value on the editText

CBA110
  • 1,072
  • 2
  • 18
  • 37

2 Answers2

1

Have you tried modifying the windowSoftInputModeproperty of your activity? In your manifest, for the related activity, set the property like so:

<activity android:name="MyActivity"
     ...
     android:windowSoftInputMode="adjustPan"
     ... >
</activity>
EscapeArtist
  • 776
  • 8
  • 15
  • The problem is not that there isn't enough space...it's just that the RelativeLayout is stuck to the bottom of the view "as it should" since it works as designed for when the keyboard is not visible (the objective of this is so that the user can then scroll the screen and the buttons are always visible even if the activity is very "tall"). The problem is that the RelativeLayout should disappear when the user is inputting information (the user's focus when the keyboard is on screen should be on inputting the data) the buttons can return after the user has dismissed the keyboard. – CBA110 Apr 13 '15 at 02:19
1
RelativeLayout footer = (RelativeLayout) findViewById(R.id.footer);
@Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);


        // Checks whether a hardware keyboard is available
        if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {

            Toast.makeText(this, "keyboard visible", Toast.LENGTH_SHORT).show();
            footer.setVisibility(View.VISIBLE)
        } else if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) {
            Toast.makeText(this, "keyboard hidden", Toast.LENGTH_SHORT).show();
            footer.setVisibility(View.INVISIBLE)
        }
    }

Note: The above code will only called for virtual keyboard also check out this Listen for keyboard show or hide event in android

Community
  • 1
  • 1
Ajeet
  • 1,540
  • 1
  • 17
  • 30
  • Hi @Ajeet thanks for the feedback, your answer looks promising. How do I listen to the keyboard (Shown/Hidden)? I'm not sure how to implement the listener for the onConfigurationChanged method. I would appreciate if you could show me how i implement this on my onCreate method. – CBA110 Apr 14 '15 at 01:15
  • Sorry, the above code doesn't work. I tried myself. Try this one https://gist.github.com/felHR85/6070f643d25f5a0b3674 – Ajeet Apr 14 '15 at 01:41