-1

How can I place the toolbar title on a different line?

For example "Getting Started" title with its subtitle is on the different line:

image

Veniamin
  • 774
  • 5
  • 12

3 Answers3

0

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);
Ben P.
  • 52,661
  • 6
  • 95
  • 123
  • By default toolbar title is placed on the same line as a toolbar, but how can I put it below the toolbar? – Veniamin Jan 20 '20 at 21:10
0

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

Emin Guliev
  • 188
  • 2
  • 11
0

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);