Displaying entire multiline EditText above keyboard. Not just writing line

Viewed 355

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!

1 Answers

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
    }
    
Related