Android: Background image resize on keyboard pop up

Manoj Fegde picture Manoj Fegde · Apr 13, 2015 · Viewed 16.4k times · Source

I am developing an application in which the background image get shrink on keyboard pop-up. My .xml is as follows :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:facebook="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background" >

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            /**
              Other stuff 
            */

        </RelativeLayout>
    </ScrollView>
</RelativeLayout>

I searched on Google and found that, to add

android:windowSoftInputMode="stateVisible|adjustPan"

in my manifest file. But its of no use.

Edit :

My Layout before key board pop up looks like :

Image 1

And after pop up like:

Image 2

Please check the difference in background image. In image 1 image is in size and in image 2 background image shrink-ed. I need the footer and background get shift upward on keyboard popup.

What I am missing or doing wrong please suggest me.

Answer

Adrian Cid Almaguer picture Adrian Cid Almaguer · Apr 19, 2015

Just use in your onCreate() this code:

protected void onCreate(Bundle savedInstanceState) {
...   
 getWindow().setBackgroundDrawableResource(R.drawable.your_image_resource);
...
}

and eliminate this line in your xml:

android:background="@drawable/background"

Read more at:

http://developer.android.com/reference/android/view/Window.html