Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent Soft Keyboard from resizing background image

I have a typical listview with an edittext and a button at the bottom of the activity.

When I click onto the edittext, the soft keyboard appears, I am able to scroll the items in the listview but it re-sizes my background image.

I have tried android:windowSoftInputMode="adjustResize" but no difference.

I have tried android:windowSoftInputMode="adjustPan". The image does not get squashed, the whole layout shifts upwards and I lose the title bar. I can only scroll the list if the list items exceed the layout size.

Basically, I want to maintain the title bar, retain the background image without re-sizing and allow scrolling of list items. Anyone managed to do this? Thanks!

like image 475
Maurice Avatar asked Mar 15 '11 03:03

Maurice


2 Answers

for listview you need to use

android:isScrollContainer="false" 

and add this to your activity in manifest.xml

android:windowSoftInputMode="adjustPan" 
like image 54
BolbazarMarme Avatar answered Sep 21 '22 17:09

BolbazarMarme


I have tried so may solutions for solving this problem. android:windowSoftInputMode="adjustPan" will make your whole screen shift with keyboard. Generally we have a title of the screen on the top. Using this flag it will also go out of the visible area, which make bad user experience. I use android:windowSoftInputMode="adjustResize" This will resize the whole screen but it will cause the same problem @Maurice state in the question.

So here is my final solution:

In Manifest

android:windowSoftInputMode="adjustResize|stateAlwaysHidden" 

In XMl

Dont Set any background here.And keep your view under ScrollView

In Java

You need to set the background to window:

getWindow().setBackgroundDrawableResource(R.drawable.bg_wood) ; 
like image 22
Gem Avatar answered Sep 22 '22 17:09

Gem