android title won't show in toolbar

getSupportActionBar().setDisplayShowTitleEnabled(true);

Setting,

app:title="@string/my_title"

within the declaration of the the android.support.v7.widget.Toolbar, hard codes the title in the toolbar.

To set the title programatically,

Toolbar toolbar = (Toolbar) findViewById(R.id.my_toolbar);
toolbar.setTitle("my title");
setSupportActionBar(toolbar);

in your activity class.


Try this .. this method works for me..!! hope it may help somebody..!!

<android.support.v7.widget.Toolbar  
 xmlns:app="http://schemas.android.com/apk/res-auto"  
 android:id="@+id/my_awesome_toolbar"  
 android:layout_width="match_parent"  
 android:layout_height="wrap_content"  
 android:background="?attr/colorPrimary"  
 android:minHeight="?attr/actionBarSize"  
 app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" >  

<TextView  
   android:id="@+id/toolbar_title"  
   android:layout_width="wrap_content"  
   android:layout_height="wrap_content"  
   android:layout_gravity="center"  
   android:singleLine="true"  
   android:text="Toolbar Title"  
   android:textColor="@android:color/white"  
   android:textSize="18sp"  
   android:textStyle="bold" />  

</android.support.v7.widget.Toolbar>  

EDIT

You can also use this.

setSupportActionBar(toolbar);
if (getSupportActionBar() != null)
      getSupportActionBar().setTitle("Toolbar title");