Wednesday 30 December 2020

Why is an AppBar adding squares to the background of my app bar

Good afternoon all,

I have been digging at this for a long time now and its time to ask for help.

I have the following AppBar

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    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/app_bar_constrained"
    android:layout_height="?android:attr/actionBarSize"
    android:layout_width="match_parent"
    android:background="@drawable/appbar_background_2020">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/campfire_app_bar"
        android:elevation="0dp"
        android:background="@drawable/appbar_background_2020"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="@id/app_bar_constrained">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:id="@+id/app_bar_collapsing"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:elevation="0dp">

            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar_2020"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:elevation="0dp">

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <TextView
                        android:id="@+id/toolbar_title"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        tools:text="Title" />

                    <TextView
                        android:id="@+id/toolbar_sub_title"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:visibility="gone"
                        tools:text="Subtitle"
                        tools:visibility="visible" />
                </LinearLayout>
            </androidx.appcompat.widget.Toolbar>

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

        <com.google.android.material.tabs.TabLayout
            android:id="@+id/tab_bar_campfire"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fadingEdge="horizontal"
            android:fadingEdgeLength="24dp"
            android:visibility="gone"
            android:layout_marginStart="24dp"
            android:layout_marginEnd="@24dp"
            android:elevation="0dp"
            android:background="@drawable/appbar_background_2020"
            app:tabBackground="?attr/selectableItemBackground"
            app:tabGravity="start"
            app:tabIndicator="@drawable/tab_indicator"
            app:tabIndicatorColor="@color/colorPrimary"
            app:tabIndicatorHeight="1dp"
            app:tabMode="scrollable"
            app:tabPaddingEnd="2dp"
            app:tabPaddingStart="2dp"
            app:tabRippleColor="@color/colorAccent"
            app:tabSelectedTextColor="@color/colorAccent"
            app:tabTextAppearance="@style/Widget.AppCompat.Light.ActionBar.TabBar"
            app:tabTextColor="@color/colorPrimary"
            tools:layout_conversion_absoluteHeight="48dp"
            tools:layout_conversion_absoluteWidth="0dp" />

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

</androidx.constraintlayout.widget.ConstraintLayout>

The layout renders with a little artifact on the bottom right and bottom left of the toolbar, where the background is curved and clipped:

Toolbar

I've previously gotten rid of this by using a ConstraintLayout instead of an AppBar, but that does not work with the animations of a CoordinatorLayout, which we are keen to use.

Please note: due to corporate considerations I have had to change colours in the above code sample.



from Why is an AppBar adding squares to the background of my app bar

No comments:

Post a Comment