I have developed one android project. In this project the text font defaults to android:sans.
Now I want to replace the default text font to roboto font for my entire project.
How can I do this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can download the Roboto font from here:
https://fonts.google.com/specimen/Roboto. [Updated 2020-01-28]
You can do it the conventional way by using
TypeFace, like this:Note: The above will have to be done in every
Activity.Alternatively, if, for example, you want to apply the Roboto font to all the
TextViews in your application, then you will need to create your own widget that extendsTextView.There is a simple way of doing this. Follow the steps from this answer on SO: https://stackoverflow.com/a/9199258/450534 (full props to leocadiotine for the solution. I have used it before and it works like a charm)
EDIT: Think of
your_namespaceas a marker for you to give it a name of your choice. For example, when integrating Admob in XML, I usexmlns:ads. You can use, for example:xmlns:fontor something descriptive.As for what the custom.ttf stands for, it is basically the font file with its extension that you need to copy in your
Assetsfolder. For example, if you are using ROBOTO-REGULAR.TTF, then replace the custom.ttf with ROBOTO-REGULAR.TTF. Using this example, the entire code should look this this: