出现键盘时 Android 工具栏会向上移动 [英] Android Toolbar moves up when keyboard appears
问题描述
我正在创建一个基于聊天的 UI 屏幕,其中有用于聊天消息的工具栏和 recyclerview,以及回复 msg 布局.
I'm creating a chat based UI screen where I have toolbar and recyclerview for chat messages, and reply msg layout.
每当 edittext 获得焦点时,它就会向上移动工具栏.相反,我想调整 recyclerview 的大小.
Whenever edittext get focus It moves up the toolbar. Instead I would like to resize the recyclerview.
一些stackoverflow 答案建议在工具栏下方放置一个空滚动视图,但它没有用.
some of the stackoverflow answers suggest to place a empty scrollview below the toolbar, but It didn't work.
<activity
android:name=".PostMessageActivity"
android:label="@string/title_activity_post_message"
android:windowSoftInputMode="stateVisible|adjustResize"
>
</activity>
我正在清单文件中将 windowSoftInputMode
设置为 stateVisible|adjustPan
.
I am setting the windowSoftInputMode
to stateVisible|adjustPan
in the manifest file.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.pasonet.yokibu.PostMessageActivity"
>
<include
android:id="@+id/toolbar_home"
layout="@layout/toolbar_home"
android:elevation="5dp"
/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar_home"
android:orientation="vertical"
android:layout_above="@+id/add_post_layout"
>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/post_msg_recyclerview"
>
</android.support.v7.widget.RecyclerView>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:padding="5dp"
android:id="@+id/add_post_layout"
android:background="#ffffff"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:elevation="5dp"
android:layout_margin="0pt"
>
<EditText
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="@+id/messageText"
android:layout_gravity="bottom"
android:layout_weight="1"
android:maxLines="4"
android:scrollbars="vertical"
android:background="@color/trasnperant"
android:hint="Type your message"
android:layout_marginBottom="4dp"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_send_black_36dp"
android:id="@+id/sendButton"
android:background="@drawable/abc_btn_default_mtrl_shape"
android:onClick="addPost"
/>
</LinearLayout>
推荐答案
问题是我在
代码>styles.xml
The problem was that I was using <item name="android:windowTranslucentStatus">true</item>
in styles.xml
要启用 adjustResize
在您的活动的父布局中添加 android:fitsSystemWindows="true"
To enable adjustResize
add android:fitsSystemWindows="true"
in your activity's parent layout
这篇关于出现键盘时 Android 工具栏会向上移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!