'Collapsing AppBar title empty until it starts collapsing

The issue is, as the title states, that when the appbar is fully visible the title isn't, and when it starts collapsing, the title appears (images below)

So here's what it looks like when the AppBar is fully visible

So here's what it looks like when the AppBar is fully and partly visible

And here's when I've started scrolling down

<?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:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appbar"
        app:layout_constraintTop_toTopOf="parent"
        android:backgroundTint="?android:attr/windowBackground"
        android:layout_height="wrap_content"
        android:layout_width="match_parent">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:toolbarId="@+id/toolbar"
            app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
            app:contentScrim="?android:attr/windowBackground">


            <androidx.appcompat.widget.Toolbar
                android:layout_gravity="center"
                android:id="@+id/toolbar"
                android:layout_height="80dp"
                android:background="?android:attr/windowBackground"
                android:layout_width="match_parent">

            </androidx.appcompat.widget.Toolbar>
        </com.google.android.material.appbar.CollapsingToolbarLayout>
    </com.google.android.material.appbar.AppBarLayout>

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:outlineProvider="none"
        android:elevation="5dp"
        app:layout_anchor="@id/nav_host_fragment_activity_main"
        app:layout_anchorGravity="bottom|center_horizontal"
        app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior"
        android:layout_height="match_parent">


    <com.google.android.material.bottomnavigation.BottomNavigationView
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintBottom_toBottomOf="parent"
                    android:layout_marginBottom="10dp"
                    android:id="@+id/nav_view"
                    android:outlineProvider="paddedBounds"
                    android:elevation="100dp"
                    android:layout_width="350dp"
                    android:layout_height="60dp"
                    android:layout_marginStart="0dp"
                    android:layout_marginEnd="0dp"
                    app:menu="@menu/bottom_nav_menu" />

    </androidx.constraintlayout.widget.ConstraintLayout>


    <fragment
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:id="@+id/nav_host_fragment_activity_main"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:defaultNavHost="true"
        app:layout_constraintBottom_toTopOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:navGraph="@navigation/mobile_navigation" />

        </androidx.coordinatorlayout.widget.CoordinatorLayout>

This is the layout for my activity

This happens regardless of fragments, so I won't be providing them for now.


        setSupportActionBar(binding.toolbar);

        AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
                R.id.navigation_home, R.id.navigation_settings, R.id.navigation_updates)
                .build();
        NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_activity_main);
        NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);

And this is the way I set the AppBar.

So my goal is just to have the title always be visible. Another bug I noticed that might be related - the title, even when visible, doesn't change regardless of fragment.



Solution 1:[1]

Turns out I needed to set

app:titleEnabled="false"

for the CollapsingToolbarLayout and it worked afterwards

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Patsore