我试图从这里设置我的自定义工具栏标题: Android toolbar center title and custom font
但标题仍然如下图所示:
这是工具栏XML:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay">
<TextView
android:id="@+id/toolbar_title"
android:textColor="#FFF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_gravity="center" />
</android.support.v7.widget.Toolbar>
JAVA:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
TextView mTitle = (TextView) toolbar.findViewById(R.id.toolbar_title);
/*Start Font Face*/
Typeface tf = Typeface.createFromAsset(getAssets(), "Limelight.ttf");
mTitle.setTypeface(tf);
/*Rnd Font Face */
setSupportActionBar(toolbar);
mTitle.setText(toolbar.getTitle());
答案 0 :(得分:0)
使用getSupportActionBar().setTitle("")
隐藏默认title
。
试试这个:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("");
TextView mTitle = (TextView) toolbar.findViewById(R.id.toolbar_title);
Typeface tf = Typeface.createFromAsset(getAssets(), "Limelight.ttf");
mTitle.setTypeface(tf);
mTitle.setText("ARTISTIC");