Android自定义Actionbar title字体

来源:互联网 发布:去掉下划线php 编辑:程序博客网 时间:2024/06/06 03:58

转自: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);


1 0
原创粉丝点击