我正试图找到一种正确的方法,为工具栏标题使用自定义字体,并将其置于工具栏中心(客户要求).
目前,我正在使用旧的ActionBar,我正在将标题设置为空值,并使用setCustomView
来放置我的自定义字体文本视图,并使用ActionBar将其居中.布局参数.
有更好的方法吗?使用新工具栏作为我的操作栏.
我正试图找到一种正确的方法,为工具栏标题使用自定义字体,并将其置于工具栏中心(客户要求).
目前,我正在使用旧的ActionBar,我正在将标题设置为空值,并使用setCustomView
来放置我的自定义字体文本视图,并使用ActionBar将其居中.布局参数.
有更好的方法吗?使用新工具栏作为我的操作栏.
要在Toolbar
中使用自定义标题,您只需记住Toolbar
只是一个奇特的视图组,因此您可以添加如下自定义标题:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_top"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?android: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>
这意味着你可以随心所欲地设计TextView
,因为它只是普通的TextView
.因此,在您的活动中,您可以这样访问标题:
Toolbar toolbarTop = (Toolbar) findViewById(R.id.toolbar_top);
TextView mTitle = (TextView) toolbarTop.findViewById(R.id.toolbar_title);