Thrower
Thrower

Reputation: 1

fix top appbar color when scrolling after implementing edge to edge

After adding top.inset to top appbar the statusbar has some kind of lag when scrolling and it changes colors. How can I solve this?

image1 image2

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    enableEdgeToEdge(SystemBarStyle.auto(Color.TRANSPARENT, Color.TRANSPARENT))

    ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.toolbar)) { v, windowInsets ->
        val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
        v.updateLayoutParams<ViewGroup.MarginLayoutParams> {
            topMargin = insets.top
        }
        WindowInsetsCompat.CONSUMED
    }
}
<com.google.android.material.appbar.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clipChildren="false"
    android:transitionName="appbar"
    tools:ignore="UnusedAttribute">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        style="?toolbarStyle"
        android:layout_width="match_parent"
        android:layout_height="?actionBarSize"
        android:background="?colorPrimary"
        android:minHeight="?actionBarSize"
        app:titleTextAppearance="@style/TextAppearance.Frames.ToolbarTitle"
        app:layout_scrollFlags="scroll|enterAlways|snap"/>

</com.google.android.material.appbar.AppBarLayout>

Upvotes: 0

Views: 176

Answers (1)

Thrower
Thrower

Reputation: 1

the problem was in android:layout_height="?actionBarSize" in androidx.appcompat.widget.Toolbar I changed it to android:layout_height="wrap_content" and the insets worked as they should

Upvotes: 0

Related Questions