I have an app with 3 activites. At my opening activity (main activity), I set the fonts for my app with the static keyword so I can reuse it. The 2 other activites get their fonts from the main activity. This pose a probelm – when a user is in lets say, activity number 3 and then return to home (desktop), without closing the application and then reopen the application – he will get the default fonts and not my custom one.
That means I will have to initilize the TypeFace in each activity in order to avoid that. My question is, what is the right to do it? should I initialize them in each activity? should I put the fonts in my main activity inside of a method and just call that method from the different activities? any other way I’m missing here?
If number of different types of views for which you want to set the custom font is small (say only
TextView), follow Custom Fonts in Android Widgets to understand how you can do it in XML, so that you do not have to do it in every activity.If you really want to share the
TypeFaceacross activities, the recommended way would be to create a sub-class ofActivitywhich contains theTypeFaceas a member variable. You would have to then use this class as the parent of all your activities.