VVB
VVB

Reputation: 7641

Toolbar title is not displaying

Toolbar title is not showing in both cases either collapsed or not. Below is my layout

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.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/coordinatorLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/appBarLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            android:background="@android:color/transparent"
            android:fitsSystemWindows="true">

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsing_toolbar"
                android:layout_width="match_parent"
                android:layout_height="@dimen/collapsing_toolbar_height"
                app:layout_scrollFlags="scroll|exitUntilCollapsed"
                app:contentScrim="?attr/colorPrimary"
                app:expandedTitleTextAppearance="@android:color/transparent"
                android:fitsSystemWindows="true">

                <ImageView
                    android:id="@+id/header_image"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/collapsing_toolbar_height"
                    android:scaleType="centerCrop"
                    android:fitsSystemWindows="true"
                    android:contentDescription="@string/app_name"
                    android:src="@mipmap/ic_launcher"
                    app:layout_collapseMode="parallax"/>

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                    android:title="@string/app_name"
                    app:layout_collapseMode="pin" />

            </android.support.design.widget.CollapsingToolbarLayout>

        </android.support.design.widget.AppBarLayout>



    <android.support.v4.widget.NestedScrollView
        android:id="@+id/scroll"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clipToPadding="false"
        android:layout_marginBottom="100dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <RelativeLayout
            android:id="@+id/rlMain"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <FrameLayout
                android:id="@+id/container"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"></FrameLayout>


        </RelativeLayout>



    </android.support.v4.widget.NestedScrollView>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <android.support.design.widget.BottomNavigationView
            android:id="@+id/bottom_navigation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            app:itemBackground="@color/faint_black"
            app:itemIconTint="@color/white"
            app:itemTextColor="@color/menu_item_color_change"
            app:menu="@menu/menu" />
    </RelativeLayout>




</android.support.design.widget.CoordinatorLayout >

Upvotes: 1

Views: 2850

Answers (5)

nnn
nnn

Reputation: 1000

Try below code:

   CollapsingToolbarLayout collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
   collapsingToolbarLayout.setTitle(getString(R.string.app_name));
   collapsingToolbarLayout.setExpandedTitleColor(ContextCompat.getColor(this, android.R.color.transparent));

Upvotes: -1

Aniruddh Ambarkar
Aniruddh Ambarkar

Reputation: 1030

Set NoActionBar theme to your atvity and then execute below code in onCrate method after setContentView

toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

Then try to set Title

Upvotes: 0

Bapusaheb Shinde
Bapusaheb Shinde

Reputation: 849

try this in your code :

<android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                    android:title="@string/app_name"
                    app:layout_collapseMode="pin" >
<TextView
      android:id="@+id/text_id"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:text="your_title"

      android:textSize="20sp"/>
</android.support.v7.widget.Toolbar>

Upvotes: 0

Blackbelt
Blackbelt

Reputation: 157447

the CollapsingToolBarLayout's title has priority on the ToolBar (yes, even tho your are not setting it). Add

 app:titleEnabled="false"

to the CollapsingToolBarLayout to disable it, and the one on the ToolBar should show up. Also it should be

  app:title

and not android:title since you are using the ToolBar from the support library

Upvotes: 12

Tavinder Singh
Tavinder Singh

Reputation: 420

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("Title Name goes here")

Upvotes: -1

Related Questions