https://kotlinlang.org logo
#compose
Title
# compose
j

Jesse Hill

12/04/2021, 1:37 AM
I was trying to make a keyboard avoiding TextField and found an unexpected (at least unexpected to me) behavior when I combined it with a Scaffold. I was thinking that if I scrolled the Column within the content of the Scaffold that the TopBar would stay in place but what I ended up with was the TopBar scrolls out of view which makes me think the whole Scaffold is scrolling and not just the Column that has the
verticalScroll
modifier. I put the code in this gist and will comment with my findings as I explore why this is happening.
c

Chris Fillmore

12/04/2021, 2:02 AM
I believe the “scrolling” here is actually the system forcing the
Window
up so that the text field is usable while the keyboard is open. (I may be wrong on this detail and someone who knows better may correct me.) You can configure the keyboard behaviour (somewhat) using
android:windowSoftInputMode
https://developer.android.com/guide/topics/manifest/activity-element#wsoft
In particular, you may try using the
adjustResize
value, which will shrink the window (rather than pan it), so your topBar should stay at the top
j

Jesse Hill

12/04/2021, 2:26 AM
Hmm, 🤔 I'm pretty sure this wasn't happening before I added the vertical scroll on the column and the
animateScrollTo
. So that makes me think it's not the window but I'll have to make sure that the Column is actually scrolling and that it's not just the window resizing. Thanks for the tip!
Using
android:windowSoftInputMode="adjustResize"
did the trick. Thanks Chris!
👍 1
2 Views