出现键盘时,Android工具栏会向上移动 [英] Android Toolbar moves up when keyboard appears
问题描述
我正在创建一个基于聊天的UI屏幕,其中具有用于聊天消息的工具栏和recyclerview,并回复味精布局.
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
要启用adjustResize
,请在活动的父级布局中添加android:fitsSystemWindows="true"
To enable adjustResize
add android:fitsSystemWindows="true"
in your activity's parent layout
这篇关于出现键盘时,Android工具栏会向上移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!