Android自定义Actionbar title字体

xiaoxiao2021-02-27  336

转自:https://segmentfault.com/a/1190000000403598

自定义有两种方法 1. setCustomView 这种方法最简单了,缺点就是如果要用Navigation Drawer的话,自定义的那部分是click不了的,只有homeButton还有icon可以获取到焦点

LayoutInflater inflator = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = inflator.inflate(R.layout.actionbar_custom, null); getActionBar().setCustomView(v); TextView textViewActionbarTitle = (TextView)v.findViewById(R.id.textView_title); textViewActionbarTitle.setTypeface(typefaceLight);

2.setTitle 这个方法就不用再弄一个布局了,好处就是可以获取到焦点

SpannableString spannableString = new SpannableString("TimeToDo"); spannableString.setSpan(new com.masaila.timetodo.font.TypefaceSpan(this, "Roboto-Light.ttf"), 0, spannableString.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); spannableString.setSpan(new AbsoluteSizeSpan(24, true), 0, spannableString.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); getActionBar().setTitle(spannableString);

转载请注明原文地址: https://www.6miu.com/read-4672.html

最新回复(0)