Push up content when clicking in edit text
AndroidAndroid Problem Overview
I have searched everywhere for a solution to my problem but cannot find a answer. Here's the problem.
I have a layout that looks like this
Now when I click in the edit text(search bar) i want the following to happen
The soft keyboard basically needs to push up the whole screens content so that the search bar is at the top and its listview is beneath it so that when the content is searched the results are displayed. I have tried setting android:windowSoftInputMode="adjustPan"
to the Activity
in the manifest but this did not work. I set a scroll view as the main container in the main layout that contains the fragments but that also did not work. I have tried adding the edit text(search bar) as a header to the list view but this also did not work. Every time the keyboard pushed up the edit text but covered the list view. Is there any way to make this work?
Android Solutions
Solution 1 - Android
Actually if you want your entire layout pan up than you should use :
SOFT_INPUT_ADJUST_PAN
meaning:
getActivity().getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
this will keep the keyboard closed and when opened it'll push your entire activity up.
Solution 2 - Android
This can be used in Fragment Class to move the Edit text up and Scroll till end.
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE|WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
This will work for sure if your Fragment Activity theme is not in FullScreen.
Hope this will help!
Solution 3 - Android
This worked for me.
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE|WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
Solution 4 - Android
I faced a similar issue, the solution was simple.
If the theme in the activity is set as Fullscreen @android:style/Theme.Holo.NoActionBar.FullScreen
, the keyboard was not pushing the contents up.
After I changed the activity to @android:style/Theme.Holo.NoActionBar
, the keyboard is now pushing the activity contents up.
Solution 5 - Android
Try this
android:windowSoftInputMode="adjustResize"
Working for me.
Solution 6 - Android
Try android:windowSoftInputMode="adjustResize"
in your manifest file.
You might need to do android:windowSoftInputMode="adjustResize|adjustPan"
... I don't really have anything comparable to your setup to test on...
Your problem is becasue of this (from the docs for adjustPan, emphasis mine):
> The activity's main window is not resized to make room for the soft > keyboard. Rather, the contents of the window are automatically panned > so that the current focus is never obscured by the keyboard and users > can always see what they are typing
Given that, your list is being obscured becasue the EditText on top has the focus. The only thing I can currently think of is to move the EditText so it is below the list. Then when pushed up, your list should still be visible above the EditText.
Solution 7 - Android
This worked for me, for fragment, just declare it in Manifest with activity:
android:windowSoftInputMode="adjustPan"
Good Luck!
Solution 8 - Android
I could not find a solution for the layout to change automatically so I had to hack it. I used the code that I found here in my main activity to detect when the keyboard is opened. I just added code to call a method that hides my top two fragments when the keyboard is opened. This isn't really what I wanted to do but it works.
Solution 9 - Android
I use this for my EditText
login:
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN|WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
Some notes about this method:
this
is referring to the context, as getActivity()
is not always preferable
.SOFT_INPUT_STATE_HIDDEN //for default hidden state when activity loads
.SOFT_INPUT_STATE_VISIBLE //for auto open keyboard when activity loads
Works everytime!
Solution 10 - Android
If anyone is still facing this issue:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:id="@+id/view"
android:fitsSystemWindows="true"
android:layout_height="match_parent">
add in your layout:
android:fitsSystemWindows="true"
I hope this solves your problem - it worked for me.
Solution 11 - Android
In kotlin: - Add this line in your Activity on Create and In Fragment onCreateView Method
activity!!.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);