I have implemented a RecyclerView
with SearchView
and Filterable
; all classes from v7
. Now there is this behavior that is annoying. Whenever the keyboard is brought up or closed the contents of the RecyclerView
goes blank. The count is still correct but the view is empty. My guess, it has something to do with the Layout
size change. Is this behavior normal or something is wrong? How to deal with it? I can show the code but don't quite know which part will be relevant so tell me what can I add here?
While typing in the question, found this from the similar questions.
Please add following line to your activity in manifest. Hope it works. android:windowSoftInputMode="adjustPan"
More precisely, add android:windowSoftInputMode="adjustPan"
in the activity
tag in AndroidMenifest.xml
where the keyboard is going to be opened.
Example:
<activity
android:name=".FManagerActivity"
android:label="@string/app_name"
android:windowSoftInputMode="adjustPan"
android:theme="@style/AppTheme.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
It is basically the behavior in which the activity reacts when the keyboard is opened or closed. adjustPan
tells the keyboard to overlay the view of the activity not disturbing it's content. Without that when the keyboard is opened the size of the activity also changes which makes the content disappear as notifyDatasetChanged()
is not called during and after the implicit actions.
Not really sure why but setting it as SOFT_INPUT_ADJUST_RESIZE solved the issue for me:
activity?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
© 2022 - 2024 — McMap. All rights reserved.
SOFT_INPUT_ADJUST_RESIZE
will resize the activity which will lead to recreation of activity (unless handling manually usingandroid:configChanges="screenSize"
). You must save activity state and retain inonCreate
. – Daveen