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.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
To update the correct answer.
firstly : set the title to false, because we are using custom view
secondly : create titleview.xml
Lastly :
DOWNLOAD FONT FILE : because i am storing the file into cloudinary so I have link on it to download it.
The Calligraphy library let's you set a custom font through the app theme, which would also apply to the action bar.
All it takes to activate Calligraphy is attaching it to your Activity context:
The default custom attribute is
fontPath
, but you may provide your own custom attribute for the path by initializing it in your Application class withCalligraphyConfig.Builder
. Usage ofandroid:fontFamily
has been discouraged.Following code will work for all the versions. I did checked this in a device with gingerbread as well as on JellyBean device
You can do this using a custom
TypefaceSpan
class. It's superior to thecustomView
approach indicated above because it doesn't break when using other Action Bar elements like expanding action views.The use of such a class would look something like this:
The custom
TypefaceSpan
class is passed your Activity context and the name of a typeface in yourassets/fonts
directory. It loads the file and caches a newTypeface
instance in memory. The complete implementation ofTypefaceSpan
is surprisingly simple:Simply copy the above class into your project and implement it in your activity's
onCreate
method as shown above.