Reputation: 239
I am trying to implement a search bar (like in GDrive or Keep Notes) with an AppBar layout, so when you scroll up it disappears from the screen, scrolls down to appear. Also, I make the status bar transparent in my style.xml file. But when I scroll up, AppBar not hiding completely, so you can see its bottom in the status bar. How can I fix this to hide it completely from the screen?
Image
AppBar
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
tools:context=".MainActivity"
android:fitsSystemWindows="true">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="@dimen/_47sdp"
app:elevation="0dp"
android:translationZ="0.1dp"
android:background="@android:color/transparent"
android:fitsSystemWindows="true">
<LinearLayout
android:id="@+id/search_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/_37sdp"
android:layout_marginTop="@dimen/_10sdp"
android:layout_marginStart="@dimen/_15sdp"
android:layout_marginEnd="@dimen/_15sdp"
android:background="@drawable/background_search"
app:layout_scrollFlags="scroll|enterAlways|snap" >
<ImageView
android:layout_width="@dimen/_20sdp"
android:layout_height="@dimen/_20sdp"
android:layout_marginTop="@dimen/_10sdp"
android:layout_marginStart="@dimen/_5sdp"
android:src="@drawable/ic_search"
app:tint="@color/colorSearchIcon"
android:layout_marginEnd="@dimen/_3sdp"
android:contentDescription="@string/search_icon"/>
<TextView
android:layout_width="match_parent"
android:layout_height="@dimen/_20sdp"
android:layout_marginStart="@dimen/_12sdp"
android:layout_marginTop="@dimen/_10sdp"
android:fontFamily="@font/opensans_regular"
android:includeFontPadding="false"
android:gravity="center_vertical"
android:text="@string/search"
android:textColor="@color/colorWhite"
android:textSize="@dimen/_13ssp"
android:clickable="true"
android:focusable="true" />
</LinearLayout>
</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
style.xml
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar.Bridge">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
Upvotes: 1
Views: 322
Reputation: 239
My problem was solved programmatically by so (original answer):
// In Activity's onCreate() for instance
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window w = getWindow();
w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
Upvotes: 1