当软键盘打开时,EditText不完全可见

时间:2016-02-10 09:59:26

标签: android android-softkeyboard emoji

单击编辑文本时,软键盘处于打开状态但编辑文本不完全可见。类似于单击表情符号图标,表情符号面板打开但编辑文本不可见。屏幕截图如下:

Screen shot 1

Screen shot 2

Screen shot 3

代码:

// 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>

请帮我解决问题。

已编辑的代码:

我已按如下方式更改了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>


    <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>

我得到以下屏幕:

screen shot 4

Screen shot 5

enter image description here

现在编辑文本完全可见,但屏幕布局无法正常工作,因为edittext文本应位于屏幕底部。但是我在edittext下面有一些空间。

1 个答案:

答案 0 :(得分:1)

在您的xml中更改或添加ScrollView作为EditText父级布局。

<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>

并将其添加到您的活动的AndroidManifest

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