1

I have an issue with soft keyboard on my project.

I have a chat screen with one EditText ,listview and a send button in my Activity.Whenever Edittext get focus It moves up the toolbar and layout.

i need to fix the toolbar and layout while showing keyboard.

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

android:orientation="vertical">

<RelativeLayout
    android:id="@+id/relheader"
    android:layout_width="fill_parent"
    android:layout_height="58dp"
    android:background="@color/blue"
    android:gravity="center"
    android:isScrollContainer="false">

    <android.support.v7.widget.Toolbar
        android:id="@+id/customtoolbar_back"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:minHeight="?attr/actionBarSize"
        android:weightSum="1">

        <TextView
            android:id="@+id/idtextheaderprojectchatwithprivatemessage"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Messages"
            android:textColor="@color/white"
            android:textSize="20dp"
            android:textStyle="bold" />
    </android.support.v7.widget.Toolbar>
</RelativeLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="5dp"
    android:layout_weight="75"
    android:orientation="vertical">


    <ListView
        android:id="@+id/listViewwallpage"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/relfb"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:cacheColorHint="@android:color/transparent"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:fadingEdge="none"
        android:listSelector="@android:color/transparent"
        android:overScrollMode="never" />

</LinearLayout>

<RelativeLayout
    android:id="@+id/relfb"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_gravity="right"
    android:layout_marginTop="5dp"
    android:background="@drawable/edittext_top_line"
    android:minHeight="42dp"
    android:paddingBottom="5dp"
    android:paddingTop="5dp">

    <EditText
        android:id="@+id/edtserach"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_marginLeft="5dp"
        android:layout_toLeftOf="@+id/lin"
        android:background="@drawable/greyedittext_background"
        android:hint="Type something..."
        android:inputType="textMultiLine"
        android:maxLength="160"
        android:singleLine="true"
        android:textColor="#000000" />

    <LinearLayout
        android:id="@+id/lin"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:orientation="vertical">

        <TextView
            android:id="@+id/tvtextcount"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:gravity="center_horizontal"
            android:hint=""
            android:textSize="12sp"
            android:visibility="gone" />

        <Button
            android:id="@+id/btnsend"
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:background="@android:color/transparent"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:text="Send"
            android:textAllCaps="false"
            android:textColor="@color/blue"
            android:textSize="18sp"
            android:textStyle="bold" />
    </LinearLayout>
</RelativeLayout>

I have Relativelayout for Toolbar and Linearlayout for listview. Any suggestions?

4 Answers4

0

Check your manifest for your Activity. You may need to reconfigure how to handle input methods. See this documentation.

Specify How Your UI Should Respond

When the input method appears on the screen, it reduces the amount of space available for your app's UI. The system makes a decision as to how it should adjust the visible portion of your UI, but it might not get it right. To ensure the best behavior for your app, you should specify how you'd like the system to display your UI in the remaining space.

Community
  • 1
  • 1
Cheticamp
  • 61,413
  • 10
  • 78
  • 131
0

in your AndroidManifest.xlm in the involved activity put :

android:windowSoftInputMode="adjustResize" 
from56
  • 3,976
  • 2
  • 13
  • 23
  • In the manifest you must put it into the activity in which you have the problem, if you put it on another place it will do nothing – from56 Aug 10 '17 at 14:10
0

In Manifest :

android:windowSoftInputMode="stateAlwaysHidden"

Add to respective activity tag.

Change Toolbar as below :

<?xml version="1.0" encoding="utf-8"?>

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@color/apptool_bar_bg"
    android:minHeight="?attr/actionBarSize"
    app:layout_scrollFlags="scroll|enterAlways|snap"
    android:theme="@style/AppTheme.Toolbar"
    app:titleTextAppearance="@style/AppTheme.Toolbar.Title"></android.support.v7.widget.Toolbar>
Jeelan
  • 173
  • 1
  • 11
0

I think you have included android:windowSoftInputMode="adjustResize" or android:windowSoftInputMode="adjustPan" in your manifest for activity.

Remove the lines if you added it in your manifest.

Bhuvanesh BS
  • 13,474
  • 12
  • 40
  • 66