1

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>
Some random IT boy
  • 7,569
  • 2
  • 21
  • 47
copycat13
  • 179
  • 1
  • 7
  • Do you need to hide the status bar or the search bar? – lpizzinidev Dec 21 '20 at 17:06
  • You have told the statusbar to be ```translucent``` which makes it partially transparent. Try removing that and setting a solid color. – private static Dec 21 '20 at 17:31
  • @PrinceAli, but I want the status bar to be `translucent` and at the same AppBar need to be hidden from the screen – copycat13 Dec 21 '20 at 18:33
  • @LucaPizzini, hide the search bar which is a child of AppBar – copycat13 Dec 21 '20 at 18:34
  • Can you post the code that you use to translate the search bar up? – lpizzinidev Dec 22 '20 at 07:45
  • @LucaPizzini, the main attribute to translate the search bar up is `app:layout_scrollFlags="scroll|enterAlways|snap"` of LineralLayout from code above. You can read more about AppBar on the material design site [here](https://material.io/components/app-bars-top/android) – copycat13 Dec 22 '20 at 13:31

1 Answers1

1

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);
}
copycat13
  • 179
  • 1
  • 7