Android toolbar center title and custom font

前端 未结 30 2692
时光说笑
时光说笑 2020-11-22 04:11

I\'m trying to figure out the right way to use a custom font for the toolbar title, and center it in the toolbar (client requirement).

At the moment, i\'m using the

30条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 05:05

    Without toolbar TextView we can customize font by using below code

    getSupportActionBar().setDisplayShowTitleEnabled(false);
    or
    getActionBar().setDisplayShowTitleEnabled(false);
    
    public void updateActionbar(String title){
        SpannableString spannableString = new SpannableString(title);
        spannableString.setSpan(new TypefaceSpanString(this,  "futurastdmedium.ttf"),
                0, spannableString.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        mToolbar.setTitle(spannableString);
    }
    

提交回复
热议问题