首页 > android如何把键盘弹出不影响布局?

android如何把键盘弹出不影响布局?

我想只把键盘和输入框那个layout弹上去
只有键盘弹出,而且toolbar的颜色会延生到下面

这是设置为adjustPan以后,会把整个界面顶上去,我只想顶输入框

activity_chat.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".activities.ChatActivity">


    <cc.h.widgets.RevealBackgroundView
        android:id="@+id/vRevealBackground"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />


    <LinearLayout
        android:id="@+id/vChatRoot"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <include layout="@layout/view_toolbar"></include>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/chatRecyclerview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:divider="#ffff0000"
            android:dividerHeight="10dp" />
            
        <LinearLayout
            android:id="@+id/llSend"
            android:layout_width="match_parent"
            android:layout_height="@dimen/send_button_height"

            android:background="@color/white"
            android:elevation="@dimen/default_elevation"
            android:gravity="center_vertical"
            android:paddingBottom="4dp"
            android:paddingLeft="8dp"
            android:paddingRight="8dp"
            android:paddingTop="8dp">

            <android.support.v7.widget.AppCompatEditText
                android:id="@+id/etSend"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:textColor="#555555"
                android:textSize="14sp" />

            <cc.haoduoyu.umaru.widgets.sendbutton.SendButton
                android:id="@+id/btnSend"
                android:layout_width="72dp"
                android:layout_height="match_parent"
                android:layout_marginBottom="2dp"
                android:layout_marginLeft="8dp"
                android:background="@drawable/btn_send"
                android:elevation="4dp"
                android:orientation="vertical" />

        </LinearLayout>


    </LinearLayout>


</FrameLayout>

view_toolbar.xml

<android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/app_bar_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:elevation="3dp">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

</android.support.design.widget.AppBarLayout>

那就不加adjustPan或者替换为adjustResize


找到了答案,可以通过在根布局加 android:fitsSystemWindows="true"属性,再通过第三方库单独设置状态栏解决 http://stackoverflow.com/questions/19897422/keyboard-hiding-edittext-when-androidwindowtranslucentstatus-true


android:windowSoftInputMode="adjustResize|adjustPan"


使用scrollview把布局嵌套进去就可以了,从图中看的话应该是把edittext用scrollview嵌套就可以了

【热门文章】
【热门文章】