Android toolbar偽タイトルが中央に

1458 ワード

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_top"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize">
<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);
  • 1
  • 2

  • If anyone else can’t remove the default app name title, do this:
    1、Call  setSupportActionBar(yourToolbar)  2、 Call getSupportActionBar().setDisplayShowTitleEnabled(false);`