[英]use custom title in toolbar with back button
I want custom text in my toolbar title. 我想在工具栏标题中使用自定义文本。 I have added it as below
我已将其添加如下
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:titleTextColor="?attr/TextColor">
<TextView
android:textColor="?attr/TextColor"
android:id="@+id/toolbar_title"
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>
and in java I have written codes like below 在java中我写了如下代码
toolbar = (Toolbar) findViewById(R.id.toolbar);
Typeface font=Typeface.createFromAsset(AuthorQuoteActivityTabs.this.getAssets(), constant.font);
TextView mTitle = (TextView) toolbar.findViewById(R.id.toolbar_title);
mTitle.setText("authorName");
mTitle.setTypeface(font,Typeface.BOLD);
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
its working fine but I am getting custom title text as well app name in toolbar. 它工作正常,但我在工具栏中获得自定义标题文本以及应用程序名称。 I want only my custom text in it.
我只想要我的自定义文字。 How can I remove default title and use only custom text in toolbar ?
如何删除默认标题并仅使用工具栏中的自定义文本?
Thanks 谢谢
当您在单独的TextView中设置标题时,您需要删除“普通”标题
getSupportActionBar().setTitle("");
Please use this code: 请使用此代码:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("Toolbar Title");
setSupportActionBar(toolbar);
Hope it helps, 希望能帮助到你,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.