Earlier there was no problem with soft input mode, but after including ConstraintLayout
, content of fragment doesn\'t move up when the keyboard appears.
Man
I encountered the same problem with you, we declared android:windowSoftInputMode="stateAlwaysHidden|adjustResize"
in the AndroidManifest.xml
, but in fact the App showed the results like adjustPan
, the contents are gone on top of the soft keyboard. So I set adjustResize
programmatically, successfully solved this problem:
Just add this line to your onCreate
:
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
I'm not sure in what Activity your fragment is located but if it's in for example InitChatActivity, just add adjustResize to your manifest, and wrap your ConstraintLayout in ScrollView or NestedScrollView:
android:windowSoftInputMode="stateHidden|adjustResize"
Everything actually works as intended with the way your layout is built -- margins are fixed distances, so your UI is simply too tall for the smaller screen. You would need to modify your layout to better adapt for a small layout -- either marking unnecessary views (e.g. the logo) as gone (ConstraintLayout will consider "gone" views as collapsed to a single point, in essence -- so the layout still works), or change some margins dimensions to a smaller value.
The usual way to build this is to use bias constraints or guidelines, instead of hard margins. Using bias or guidelines (in percent mode) would allow you to have more of a "spring"-like behaviour to react better to dimension changes. Typically a layout will be a mix of hard margins and bias / guidelines.
To sum up, your options are:
GONE
when detecting the keyboard