Reputation: 2693
I implemented CoordinatorLayout
with AppBarLayout
and Toolbar
to hide toolbar when scrolling and everything working greet.
The problem appears when i implemented search view.
Here is my activity_main
layout:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<View
android:id="@+id/appbar_bottom"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/transparent"
android:visibility="invisible"/>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
And my fragment_layout
:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/projects_swipe_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/projects_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"/>
</android.support.v4.widget.SwipeRefreshLayout>
Normal layout RecyclerView
The problem here when keyboard is hidden.
Upvotes: 2
Views: 1483
Reputation: 417
You can control the expandable behavior of the appBarLayout :
first By putting these lines in Manifest, you disable the appbar collapse effect due to the keyboard when it shows and when it hides.
<activity android:name="MyActivity"
...
android:windowSoftInputMode="adjustNothing"
...
</activity>
Then, simply expand/collapse appbar whenever you want :
appbar.setExpanded(true); / appbar.setExpanded(false);
you could collapse when EditText hasFocus, and expand when outter views get touch..
(someView.setOnTouchListener ...)
Upvotes: 1
Reputation: 211
Answered here: Android : Showing keyboard moves my components up, i want to hide them instead
Add android:windowSoftInputMode="adjustPan" to manifest - to the corresponding activity:
<activity android:name="MyActivity"
...
android:windowSoftInputMode="adjustPan"
...
</activity>
Upvotes: 0