Add the title directly in the Toolbar
using the property
app:title="titulo toolbar"
for example:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:title="titulo toolbar"/>
or programmatically:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("titulo toolbar");
Update:
Since the layouts of your Activity you are loading a include
which has a Toolbar
defined:
<include layout="@layout/toolbar"
android:id="@+id/toolbar" />
Center Text in Toolbar:
If you want to center the text within your Toolbar
you could do it by adding a TextView
within your Toolbar
, and define the property android:layout_gravity="center_horizontal"
:
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.Light"
app:popupTheme="@style/Popup">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="titulo Toolbar!!!"
android:gravity = "center"
android:id="@+id/toolbar_title" />
</android.support.v7.widget.Toolbar>
Here is an answer similar on the English site
Change text in Toolbar:
To change the text look for the TextView
reference and change the text using the setText()
method
TextView titleToolbar = findViewById(R.id.toolbar_title);
titleToolbar.setText("titulo toolbar");