【问题标题】:Custom Toolbar Title not work correctly自定义工具栏标题无法正常工作
【发布时间】:2017-05-09 20:06:55
【问题描述】:

我正在尝试从这里设置自定义工具栏标题: 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());

【问题讨论】:

    标签: android xml toolbar titlebar


    【解决方案1】:

    使用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");
    

    【讨论】:

    • 使用 mTitle.setText("NEW TITLE") 代替 mTitle.setText(toolbar.getTitle());
    猜你喜欢
    • 2016-09-23
    • 2014-06-10
    • 1970-01-01
    • 2016-12-11
    • 1970-01-01
    • 2014-03-18
    • 1970-01-01
    • 2016-07-28
    • 1970-01-01
    相关资源
    最近更新 更多