25

My activity's layout is as shown below.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:orientation="vertical">

   <FrameLayout android:id="@+id/title_bar"
      android:layout_width="fill_parent"
      android:layout_height="25dip"
      android:background="@drawable/bg_title" />

   <LinearLayout android:id="@+id/main"
      android:width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_weight="1">
         <ListView android:id="@+id/android:list"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
         <TextView android:id="@+id/android:empty"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
      </FrameLayout>
   </LinearLayout>

   <LinearLayout
      android:layout_width="fill_parent"
      android:layout_height="50dip" >
      <EditText android:id="@+id/query"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content" 
         android:hint="Enter some search terms"
         android:singleLine="true" 
         android:layout_weight="1" />
      <Button android:id="@+id/btn_hide"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:background="@drawable/btn_hide"
         android:layout_marginLeft="6dip" />
   </LinearLayout>
 </LinearLayout>

So, the search box is fixed to the bottom of the screen.

But, when user clicks the EditText, Soft Keyboard shows up and pushes the layout out of the screen except the search box.

I'm just starting out with Android, so am I doing anything wrong here??

Joe Doyle
  • 6,363
  • 3
  • 42
  • 45
venkatagiri
  • 378
  • 1
  • 4
  • 8

3 Answers3

51

Try adding the following for your activity in Manifest:

android:windowSoftInputMode="adjustPan"
Asahi
  • 13,378
  • 12
  • 67
  • 87
  • 6
    Thanks. This was the attribute i was looking for. But, as it's value, I had to use "adjustResize" to make it work as I needed. – venkatagiri Nov 07 '10 at 07:24
  • 2
    Hi, i too have the same issue. But i cannot use "adjustResize". because i have tabbar at the bottom. if i use resize tabbar will be pushed to above soft keypad. i dont want to happen that. so if any one is having a solution please help me. – Raj Apr 17 '12 at 05:01
14

For those that are interested, the difference between android:windowSoftInputMode="adjustPan" and android:windowSoftInputMode="adjustResize" :

"adjustResize"

The activity's window is resized to make room for the soft keyboard on screen.

"adjustPan"

The contents of the activity's window are automatically panned so that the current focus is never blocked by the keyboard. This is so the user can see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.

Android Documentation

Cited link

Community
  • 1
  • 1
Ushal Naidoo
  • 2,704
  • 1
  • 24
  • 37
5

@Raj If you are working with a tabbed application you have to add

android:windowSoftInputMode="adjustPan"

on the Activity where you are adding the tabs, this would most probably be your launcher activity.

Here is a snippet from my code

<activity
   android:label="@string/app_name"
   android:name=".MainActivity" android:windowSoftInputMode="adjustPan">
   <intent-filter >
     <action android:name="android.intent.action.MAIN" />
     <category android:name="android.intent.category.LAUNCHER" />
   </intent-filter>

Mushtaq Jameel
  • 7,053
  • 7
  • 33
  • 52