60

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

Image is here

Now when I click in the edit text(search bar) i want the following to happen

Image is here

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?

the-ginger-geek
  • 7,041
  • 4
  • 27
  • 45

11 Answers11

76

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.

jinkal
  • 1,622
  • 16
  • 21
David Fischer
  • 1,320
  • 12
  • 14
  • But layout push up when enter the first character in the edit box. – Nivedh Dec 07 '15 at 04:22
  • 5
    `adjustpan` is working fine but at the same time, I also want my buttons which are at the bottom to be placed over the keyboard( which is basically achieved using `adjustResize` but then it doesn't pushes the whole layout upwards which ultimately hides the textbox in which am entering data. Can anyone help? – driftking9987 Mar 05 '16 at 22:04
  • im looking for the same driftking – filthy_wizard Jul 06 '16 at 20:38
  • similar issue. i have an editext, below it radiobuttons to select emoji keyboard or regular softinputkeyboard. in some activities only the edittext is pushed upward when the edittext is selected. this hides the buttons underneath – filthy_wizard Jul 22 '16 at 07:45
  • i found if i remove this line from my oncreate method Window.SetSoftInputMode(SoftInput.StateAlwaysHidden); the edittext pushes up with its footer attached always. iam using xamarin by the way – filthy_wizard Jul 22 '16 at 08:04
  • but where i have to write this code... i mean in onCreate method? – Akshay Kumar Mar 26 '17 at 13:47
20

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!

Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
Dunken_sai
  • 343
  • 3
  • 7
11

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.

Tom
  • 15,798
  • 4
  • 37
  • 48
Chandru
  • 121
  • 1
  • 4
11

This worked for me.

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE|WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
Madhav
  • 283
  • 3
  • 13
10

Try this

android:windowSoftInputMode="adjustResize"

Working for me.

Garg
  • 2,731
  • 2
  • 36
  • 47
Neo
  • 3,546
  • 1
  • 24
  • 31
8

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.

Barak
  • 16,318
  • 9
  • 52
  • 84
  • Thanks for the reply. I have tried that, did not work. The re-size works but it causes the content to be squished in at the top of the screen and that looks really bad, also the listview content is not displayed when adjustResize is used. – the-ginger-geek Jul 02 '12 at 12:35
  • Updated my answer, not a real solution, but a possible workaround. – Barak Jul 02 '12 at 13:05
  • Hi Barak I have tried moving the EditText below the listview but this did not work. I also thought it should but it just pushed the EditText over the listview and hid all the content of the listview. – the-ginger-geek Jul 03 '12 at 05:55
4

This worked for me, for fragment, just declare it in Manifest with activity:

android:windowSoftInputMode="adjustPan"

Good Luck!

Garg
  • 2,731
  • 2
  • 36
  • 47
  • I have several scroolviews and relative layouts inside scrollview where my edittext views are. This definitely work. I thought I would have to put it in every edittext, turns out this is so simple,hehe. ♥ – iamjoshua Jan 07 '18 at 17:50
3

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.

Community
  • 1
  • 1
the-ginger-geek
  • 7,041
  • 4
  • 27
  • 45
1

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!

Petro
  • 3,484
  • 3
  • 32
  • 59
1

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.

Manish Malviya
  • 546
  • 2
  • 15
0

In kotlin: - Add this line in your Activity on Create and In Fragment onCreateView Method

activity!!.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
Pascal R.
  • 2,024
  • 1
  • 21
  • 35
safal bhatia
  • 195
  • 1
  • 5