2

Recently, I've been working on a chat UI, in which I have some custom component, an EditText mainly, for the user to write the message on. The first image would be an example layout, not necessarily the one I'm using, but the concept is the same. The other two images, are the current state of the UI, and what I would like to achieve.

enter image description here

FYI, this is a Fragment, within an Activity, which has a BottomNavigation component. I make this clarification, because, should I just apply the windowSoftInputMode="adjustResize" I'm afraid the BottomNavigation component will also appear above the keyboard, as would the button.

So I'm guessing the question is: how do I tell the keyboard to stay below the entire EditText? Is this even possible? That's my main concern.

Thanks!

Miguel Lasa
  • 133
  • 1
  • 3
  • 12
  • 1
    Does this answer your question? [Hiding ‘Bottom Navigation Bar’ whilst keyboard is present - Android](https://stackoverflow.com/questions/43115510/hiding-bottom-navigation-bar-whilst-keyboard-is-present-android) – ADM Jan 15 '21 at 16:18
  • 1
    Use the accepted answer in the link . You should change the softInput mode to `adjustResize` u can do it at runtime also or just have it in manifest whichever fits your need. For `BottomNavigation` use the link to make it visible and gone when keyboard visibility gets changed . This is the only solution for this as far as i know. – ADM Jan 15 '21 at 16:20
  • @ADM and the Button should also be Visible/Gone when the keyboard appears? I'll check the link out. Thanks. – Miguel Lasa Jan 15 '21 at 17:56

1 Answers1

0

After going down the rabbit hole quite a bit, I basically found three approaches:

  1. Using ViewTreeObserver.OnGlobalLayoutListener, mentioned in the question ADM provided above, which in turn, refers to this post here.

  2. Taking advantage of this library, which for many, seemed to do the trick.

  3. Finally, the one I've seen the least out there. For devices with API level 30, or above, you can use the following piece of code to listen to changes in keyboard visibility. It is described in full, with many other useful new things, here:

    ViewCompat.setOnApplyWindowInsetsListener(view) { v, insets ->
        val imeVisible = insets.isVisible(Type.ime())
        // do something with imeVisible value
    }
    
Miguel Lasa
  • 133
  • 1
  • 3
  • 12