简体   繁体   中英

Prevent Keyboard layout hiding toolbar but reveal scroll content

Best description for my issue was at

Keyboard layout hiding android action bar?

And I will paste-quote here: " I have this problem also but the difference is, i have a list above my edittext and can't use a scrolling container. If I use adjustResize when the edittext is focused it appears above the list and the last items from the list get obscured (list is not pushed up). If I don't use adjustResize on the other hand, when the edittext is focused it pushes everything up but the acionbar is hidden and also I cannot scroll to the top of the list. Can someone share a solution for this? "

在此处输入图片说明 在此处输入图片说明

So

  • I have a toolbar
  • then a chat content
  • and then a bottom bar for sending a message (editText and a button)

Now, when I tap on an ediText, and soft keyb opens up, I do NOT want my toolbar to collapse and hide, but I do want my chat content to scroll up, so above the bottom entry I will see the last messages from chat content (in listView).

I've tried a number of combinations for Activity adjustResize or adjustPan, but none of them was working. Even wrapped toolbar in CoordinatorLayout and AppBarLayout, but still, no results. Either my content gets pushed/scrolled correctly but toolbar hides OR toolbar stays but softKeyboard overlaps last couple of messages.

The solution I share is a workaround. I had implemented a function scroll(), to scroll my content if a new message arrives, so that was one function I implemented before. I was missing the other part and that is, detect when a softKeyboard was open so I can scroll my content.

That was easy to find here on How to check visibility of software keyboard in Android?

I hope someone will find this workaround useful and sleep at least a couple more hours.

Note: Animation of sliding content up is not consistent with softKeyboard sliding up. After keyboard is opened, then I do scroll, which is not in-sync. It is just a snap. But I don't care about that until I find a better solution for orchestrating this event using a native Android component or layout.

所有上述最简单,最佳的解决方案是简单地使用以下内容:

listView.setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM