Android 当软键盘出现时,如何将工具栏固定在顶部

Android 当软键盘出现时,如何将工具栏固定在顶部,android,android-layout,Android,Android Layout,我已经创建了一个聊天应用程序。我已经附上了截图。当键盘处于活动状态时,工具栏不可见。我在stack overflow和其他网站上尝试了各种解决方案,但似乎都不适合我。我已附上代码。请帮忙。 1.布局代码: <?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout android:id="@+id/main_content" xmlns:tools

我已经创建了一个聊天应用程序。我已经附上了截图。当键盘处于活动状态时,工具栏不可见。我在stack overflow和其他网站上尝试了各种解决方案,但似乎都不适合我。我已附上代码。请帮忙。 1.布局代码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    android:id="@+id/main_content"
    xmlns:tools="http://schemas.android.com/tools"
    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="wrap_content">
    <RelativeLayout
        android:id="@+id/layout_chat_container"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        tools:ignore="RtlHardcoded"
        android:layout_gravity="bottom"
        android:isScrollContainer="false"
        android:background="@color/newColor2">

        <include
            android:id="@+id/app_bar"
            layout="@layout/toolbar"
            android:layout_width="match_parent"
            android:layout_height="@dimen/toolbar_height" />
        <se.emilsjolander.stickylistheaders.StickyListHeadersListView
            android:id="@+id/list_chat_messages"
            style="@style/ListViewWithoutDividerStyle"
            android:listSelector="@android:color/transparent"
            android:fastScrollEnabled="true" />
        <ProgressBar
            android:id="@+id/progress_chat"
            style="@style/CenterProgressBarStyle"
            android:visibility="gone" />

        <LinearLayout
            android:id="@+id/layout_attachment_preview_container"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_above="@+id/layout_chat_send_container"
            android:background="@color/colorPrimary"
            android:orientation="vertical"
            android:visibility="gone">
            <View
                android:id="@+id/divider_chat_attachments"
                style="@style/HorizontalDividerStyle" />

            <com.flock.android.quickblox.chat.ui.widget.AttachmentPreviewAdapterView
                android:id="@+id/adapter_view_attachment_preview"
                style="@style/MatchWidth" />
        </LinearLayout>
        <View
            android:id="@+id/divider_chat"
            style="@style/HorizontalDividerStyle"
            android:layout_above="@+id/layout_chat_send_container" />
        <LinearLayout
            android:id="@+id/layout_chat_send_container"
            style="@style/MatchWidth"
            android:layout_alignParentBottom="true"
            android:background="@color/colorPrimary"
            android:orientation="horizontal">
            <ImageButton
                android:id="@+id/button_chat_attachment"
                style="@style/BorderlessImageButtonStyle"
                android:contentDescription="@null"
                android:layout_gravity="center_vertical"
                android:onClick="onAttachmentsClick"
                android:src="@mipmap/ic_action_attachment"
                android:visibility="gone" />
            <EditText
                android:id="@+id/edit_chat_message"
                style="@style/WeightWidth"
                android:layout_height="wrap_content"
                android:hint="@string/chat_edit_text_hint"
                android:scrollHorizontally="false"
                android:textColorHint="@color/colorActionMode"
                android:inputType="textShortMessage|textMultiLine|textCapSentences"
                android:maxLength="1024"
                android:textColor="@color/white"
                android:layout_marginLeft="@dimen/view_margin_small"
                android:singleLine="false" />
            <ImageButton
                android:id="@+id/button_chat_send"
                style="@style/BorderlessImageButtonStyle"
                android:contentDescription="@null"
                android:layout_gravity="center_vertical"
                android:onClick="onSendChatClick"
                android:src="@mipmap/ic_sent"
                android:text="@string/chat_send" />
        </LinearLayout>
    </RelativeLayout>
</android.support.design.widget.CoordinatorLayout> 


尝试下面的代码,确保您的布局在滚动视图中,因为adjustResize始终调整活动主窗口的大小,以便为屏幕上的软键盘腾出空间

  <activity
        android:name=".YourActivity"
        android:windowSoftInputMode="stateHidden|adjustResize">

删除标志
getWindow().setFlags(WindowManager.LayoutParams.flag\u全屏,WindowManager.LayoutParams.flag\u全屏)用于全屏活动,如果代码中有

检查清单中的活动标记中是否应该有android:WindowsOfInputMode=“stateHidden | adjustResize”


现在试试……希望它能有所帮助

我已经尝试了各种解决堆栈溢出的方法,你尝试了什么?我在代码中看不见。你是否尝试过android:WindowsOfInputMode=“stateHidden | adjustPan”
我尝试过,但无法工作。。。我遇到了同样的问题,给出的解决方案只解决了我的问题…在您的情况下,如果它不能解决您的问题,请尝试使用工具栏设置setActionBar,并在xml中尝试为StickyListHeadersListView提供以下(@+id/app_bar)属性。。。