My application is a chat application, and its UI is:
Header of the app
List View
Chat message, input box, and send button
But the problem is when I click the edit text, the soft keyboard comes and pushes everything up, but I need the header to stay on the screen. I've attached the simplified problem images and UI code here. (I can't post multiple links or images in this post because I'm new to Stack Overflow.)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<TextView android:text="Header contents" android:layout_width="fill_parent"
android:textSize="20sp" android:gravity="center_horizontal"
android:layout_height="wrap_content" />
<ListView android:id="@android:id/list" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1" />
<EditText android:text="" android:layout_gravity="bottom"
android:id="@+id/EditText01" android:layout_width="fill_parent"
android:layout_height="wrap_content"></EditText>
</LinearLayout>
Android has this requirement in the default messaging app.
Does anyone have any ideas?
How do I stop my keyboard from pushing up my screen? Add android:windowSoftInputMode="stateHidden|adjustPan" in required activity of your manifest file . This makes keyboard appear overlaying content, without making layout to recalculate it's height.
Scrolling up scrollview when keyboard is shown We can add bottom padding into the scrollview using its contentInset property, so the content inside will be moved up when a keyboard is shown. You can think of contentInset as an additional padding extending from the content area edges.
The Android system shows an on-screen keyboard—known as a soft input method—when a text field in your UI receives focus.
The question is quite old, but anyhow - one way to fix this is to put everything that comes below the header within a ScrollView.
Example:
<!-- Both elements below are children of a parent RelativeLayout -->
<RelativeLayout
android:id="@+id/custom_action_bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:isScrollContainer="false" >
<!-- Header goes here. -->
<!-- This part remains fixed even with the keypad popping up. -->
</RelativeLayout>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/custom_action_bar"
android:isScrollContainer="true" >
<!-- Rest of the UI -->
<!-- This part scrolls to accommodate the keyboard -->
</ScrollView>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With