Deepak Rattan
Deepak Rattan

Reputation: 1299

EditText is not completely visible when the soft keyboard is on

On clicking edit text soft keyboard is on but edit text is not completely visible .Similarly on clicking emoji icon ,a panel of emoji is on but edit text is not visible .Screenshots are given below:

Screen shot 1

Screen shot 2

Screen shot 3

Code:

// On clicking the edit text Emoji panel will be hidden
    edMessage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            hideEmoji = true;
            hideEmojiPopUp(hideEmoji);
            showKeyboard(edMessage);
        }
    });

// Hiding the FrameLayout containing the list of Emoticons
public void hideEmojiPopUp(boolean hideEmoji) {
    FrameLayout frameLayout = (FrameLayout) findViewById(R.id.emojicons);
    frameLayout.setVisibility(View.GONE);
}

 //Show the soft keyboard
public void showKeyboard(EditText editText) {
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
    //setHeightOfEmojiEditText();
}

Manifest.xml

<activity
        android:name=".activity.SingleChatActivity"
        android:windowSoftInputMode="adjustResize">
    </activity>

activity_singlechat.xml

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="match_parent"
    android:background="@drawable/bg_single_chat"
    android:orientation="vertical"
    android:weightSum="1">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbarSingleChat"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#09436B"
        android:elevation="6dp"
        android:minHeight="?attr/actionBarSize"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    <ListView
        android:id="@+id/lv_message"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight=".90"
        android:divider="@null"
        android:stackFromBottom="true"
        android:transcriptMode="alwaysScroll"></ListView>

    <com.rockerhieu.emojicon.EmojiconEditText
        android:id="@+id/edtMessage"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_gravity="bottom"
        android:layout_weight=".10"
        android:background="#FFFFFF"
        android:drawableLeft="@drawable/emoticons"
        android:drawablePadding="@dimen/padding10"
        android:drawableRight="@drawable/send"
        android:hint="Type your message ..."
        android:paddingBottom="@dimen/padding10"
        android:paddingLeft="@dimen/padding10"
        android:paddingRight="@dimen/padding10"
        android:paddingTop="@dimen/padding10" />

    <View
        android:id="@+id/view"
        android:layout_width="wrap_content"
        android:layout_height="10dp"
        android:visibility="gone" />

    <FrameLayout
        android:id="@+id/emojicons"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight=".00"
        android:visibility="gone" />
</LinearLayout>

Please help me to fix the issue.

Edited Code:

I have changed the xml file as follows:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="match_parent"
    android:background="@drawable/bg_single_chat"
    android:orientation="vertical"
    android:weightSum="1">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbarSingleChat"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#09436B"
        android:elevation="6dp"
        android:minHeight="?attr/actionBarSize"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    <ListView
        android:id="@+id/lv_message"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight=".90"
        android:divider="@null"
        android:stackFromBottom="true"
        android:transcriptMode="alwaysScroll"></ListView>


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <com.rockerhieu.emojicon.EmojiconEditText
                android:id="@+id/edtMessage"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_gravity="bottom"
                android:layout_weight=".10"
                android:background="#FFFFFF"
                android:drawableLeft="@drawable/emoticons"
                android:drawablePadding="@dimen/padding10"
                android:drawableRight="@drawable/send"
                android:hint="Type your message ..."
                android:paddingBottom="@dimen/padding10"
                android:paddingLeft="@dimen/padding10"
                android:paddingRight="@dimen/padding10"
                android:paddingTop="@dimen/padding10" />

            <FrameLayout
                android:id="@+id/emojicons"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight=".00"
                android:visibility="gone" />
        </LinearLayout>
    </ScrollView>
</LinearLayout>

i am getting the following screens:

screen shot 4

Screen shot 5

enter image description here

Now edit text is completely visible but layout of the screen is not working properly as edittext text should be at the bottom of the screen .But i am getting some space below edittext.

Upvotes: 0

Views: 982

Answers (1)

Rashid
Rashid

Reputation: 1740

Change or Add ScrollView as your EditText parent layout in your xml.

<ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    <LinearLayout
            android:layout_width="match_parent" 
            android:layout_height="match_parent">
        <EditText 
                android:layout_width="match_parent" 
                android:layout_height="match_parent"/>
    </LinearLayout>

</ScrollView>

and add this to your activity's AndroidManifest

android:configChanges="keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="stateHidden|adjustResize"

Upvotes: 1

Related Questions