Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
594 views
in Technique[技术] by (71.8m points)

Android Toolbar moves up when keyboard appears

I'm creating a chat based UI screen where I have toolbar and recyclerview for chat messages, and reply msg layout.

Whenever edittext get focus It moves up the toolbar. Instead I would like to resize the recyclerview.

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>

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>

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The problem was that I was using <item name="android:windowTranslucentStatus">true</item> in styles.xml

To enable adjustResize add android:fitsSystemWindows="true" in your activity's parent layout


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...