Installing Roboto on my global font for my app in Android Studio

I am building a small Android app and want the font for the whole app and all text to be no matter where Roboto is, without me having to change it. So far, the answer to this question hasn't helped me.

I created an assets folder and a fonts folder, but I don't want it to import it over and over again in every action / text.

Is there a way I can do this?

+3


source to share


2 answers


The answer is yes.

Roboto Global Light for TextView and Buttonclasses.

<style name="AppTheme" parent="AppBaseTheme"> 
    <item name="android:textViewStyle">@style/RobotoTextViewStyle</item> 
    <item name="android:buttonStyle">@style/RobotoButtonStyle</item> 
</style> 

<style name="RobotoTextViewStyle" parent="android:Widget.TextView"> 
    <item name="android:fontFamily">sans-serif-light</item> 
</style> 

<style name="RobotoButtonStyle" parent="android:Widget.Holo.Button"> 
    <item name="android:fontFamily">sans-serif-light</item> 
</style>

      

Just select the style you want from the themes.xml list, then create your own style based on the original. Finally, apply the style as the application theme.



<application android:theme="@style/AppTheme" > </application>

      

It will only work with embedded fonts like Roboto, but that was the question. For custom fonts (such as those loaded from assets) this method will not work.

And you can use this text view class in your XML file. Have a look at this thread fooobar.com/questions/14359 / ...

+2


source


Ok, I found the answer to my question as well as the reason why I didn't understand the answer posted earlier.

1.) The file you want to modify is global styles.xml found in: home> permissions> values> style.xml

If you have already chosen a theme for your application in the design window of your main activity, the file will already contain:

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
        <!-- Customize your theme here. -->

</resources>

      

As the comment says, you can customize your application.



Add the styles you want, like tomrozb's answer: fooobar.com/questions/14359 / ...

then add theme to AndroidManifest.xml if not already there.

<application android:theme="@style/AppTheme" >

      

The AppTheme part corresponds to the name of the style in styles.xml.

My biggest problem was that I didn't know which files to add what to. So now I am getting this, and I hope someone else finds it useful :)

+1


source







All Articles