How can I place the toolbar title on a different line?
For example "Getting Started" title with its subtitle is on the different line:
How can I place the toolbar title on a different line?
For example "Getting Started" title with its subtitle is on the different line:
Assuming you are using an android.widget.Toolbar
, you are looking for the subtitle. This can be set in XML:
<Toolbar
android:subtitle="@string/your_string_here"
.../>
Or in code:
Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setSubtitle(R.string.your_string_here);
If you are using an AppCompat theme that provides a default toolbar, you can access it via getSupportActionBar()
. This returns an android.support.v7.app.ActionBar
(or androidx
equivalent), but the syntax is the same:
ActionBar actionbar = getSupportActionBar();
actionbar.setSubtitle(R.string.your_string_here);
You might actually want a Collapsing toolbar. Have a look here, sample code available there as well
Otherwise you have to customise the toolbar
Hint: Toolbar can be a container as well. Example
You have to create custom toolbar,so easily create your own design perfection:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_top"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="@color/action_bar_bkgnd"
app:theme="@style/ToolBarTheme" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Toolbar Title"
android:layout_gravity="center"
android:id="@+id/toolbar_title" />
</android.support.v7.widget.Toolbar>
This means that you can style the TextView however you would like because it's just a regular TextView. So in your activity you can access the title like so:
Toolbar toolbarTop = (Toolbar) findViewById(R.id.toolbar_top);
TextView mTitle = (TextView) toolbarTop.findViewById(R.id.toolbar_title);