How to Set a Custom Font in the ActionBar Title?

后端 未结 17 1672
面向向阳花
面向向阳花 2020-11-22 09:46

How (if possible) could I set a custom font in a ActionBar title text(only - not the tab text) with a font in my assets folder? I don\'t want to use the android:logo option.

17条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 10:19

    To add to @Sam_D's answer, I had to do this to make it work:

    this.setTitle("my title!");
    ((TextView)v.findViewById(R.id.title)).setText(this.getTitle());
    TextView title = ((TextView)v.findViewById(R.id.title));
    title.setEllipsize(TextUtils.TruncateAt.MARQUEE);
    title.setMarqueeRepeatLimit(1);
    // in order to start strolling, it has to be focusable and focused
    title.setFocusable(true);
    title.setSingleLine(true);
    title.setFocusableInTouchMode(true);
    title.requestFocus();
    

    It seems like overkill - referencing v.findViewById(R.id.title)) twice - but that's the only way it would let me do it.

提交回复
热议问题