This library provides a way to set default (downloadable) fonts using Calligraphy methods.
This library supports Downloadable Font of Support Library 26.
This library based on chrisjenx/Calligraphy
And this library use Android Support Library
implementation 'com.github.takahirom.downloadable.calligraphy:downloadable-calligraphy:[Latest Version]'
You can use Bundled Font or Downloadable Font.
You can add Downloadable Font using Android Studio.
https://developer.android.com/guide/topics/ui/look-and-feel/downloadable-fonts.html#via-android-studio
Add your custom fonts to res/font/
. You can see the Font Resource document.
https://developer.android.com/guide/topics/resources/font-resource.html
<TextView android:fontFamily="@font/my_font"/>
Define your default font using CalligraphyConfig
, in your Application
class in the #onCreate()
method.
@Override
public void onCreate() {
super.onCreate();
CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
.setDefaultFont(R.font.roboto_regular)
.build()
);
//....
}
Wrap the Activity
Context:
@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
}
You're good to go!
<TextView
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/roboto_bold"/>
The CalligraphyFactory
looks for the font in a pretty specific order, for the most part it's
very similar to how the Android framework resolves attributes.
View
xml - attr defined here will always take priority.Style
xml - attr defined here is checked next.TextAppearance
xml - attr is checked next, the only caveat to this is IF you have a font defined in theStyle
and aTextAttribute
defined in theView
theStyle
attribute is picked first!Theme
- if defined this is used.Default
- if defined in theCalligraphyConfig
this is used of none of the above are found OR if one of the above returns an invalid font.
To our knowledge (try: grep -r -e "void set[^(]*(Typeface " <android source dir>
) there are two standard Android widgets that have multiple methods to set typefaces. They are:
- android.support.v7.widget.SwitchCompat
- android.widget.Switch
Both have a method called setSwitchTypeface
that sets the typeface within the switch (e.g. on/off, yes/no). SetTypeface
sets the typeface of the label. You will need to create your own subclass that overrides setTypeface
and calls both super.setTypeface
and super.setSwitchTypeface
.
Copyright 2013 Christopher Jenkins,
Modifications Copyright (C) 2017 takahirom
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.