I'm developing a chat screen. It consists of CollapsingToolbarLayout for user profile image, RecyclerView for messages list and an edit box to send messages. I can't figure out if it's possible to pin edit box to the bottom screen and prevent it from scrolling with the rest of the screen?
I achieved almost what I want if I wrap CoordinatorLayout in a vertical LinearLayout and put EditText outside of CoordinatorLayout. However in this case keyboard behavior is detached from RecyclerView - it doesn't scroll up/down when you open keyboard.
If I try to put EditText inside CoordinatorLayout it scrolls out of screen, I don't know if there is any special Behavior I need to set for it
My Layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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:id="@+id/keyboard_listener"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinator"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
<RecyclerView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:clipToPadding="false"
android:focusableInTouchMode="true"
android:paddingBottom="20dp"
android:scrollbarStyle="outsideOverlay"
android:scrollbars="vertical"
android:transcriptMode="normal"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
>
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/screen_toolbar_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
app:titleEnabled="false"
>
<FrameLayout
android:id="@+id/toolbar_fragment_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<Toolbar
android:id="@+id/screen_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@android:color/transparent"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_collapseMode="pin"
/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
<EditText
android:id="@+id/messageEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:hint="@string/send_hint"
android:inputType="textCapSentences|textMultiLine"
android:maxLength="2000"
android:maxLines="4"
android:padding="10dp"
android:textSize="14sp"/>
</LinearLayout>
Add this in your EditText, my friend, just like a floatingActionButton
app:layout_anchor="@id/your bottom view id"
app:layout_anchorGravity="bottom|right|end"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With