I have an example of how to change the font to a text, but what I need is to apply it globally so I don't have to put it on each TextView
:
public class ActividadEjemplo extends AppCompatActivity {
TextView text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ejemplo);
text = (TextView)findViewById(R.id.txt1);
String font_path = "font/Quicksand-Regular.ttf";
Typeface fuente = Typeface.createFromAsset(getAssets(),font_path);
text.setTypeface(fuente);
}
}
To use Calligraphy quickly, create your project and add the reference to the library
Then you create a class that does an extends to the Application class
MyApplication.java
Then in your AndroidManifest.xml file, inside the application tag in the android:name property, you put the name of your previously created class, looking like this:
Then inside your project in the assets directory you place your fonts, in my case I have assets/fonts/Roboto-Regular.ttf . And then in your Main class you add the following:
This way you make all your components inside the activity load the default font, which in this case is Roboto-Regular.ttf .
To do it globally I recommend using Calligraphy . You can define global fonts for the entire application or even assign fonts found in your assets within the XML.
UPDATE
First you need to add it to your gradle file as a dependency:
You must have a class that extends from
Application
to which you must add the following code in its methodonCreate()
:Finally in each
Activity
one that you want to have the default fonts, you have to add the following code:All this information is also available in the Github repository of this library.