Applying custom font to the whole Android Application?

Before you jump with negative comments/votes, I will specify that I have read every question on `Stackoverflow regarding this topic, and have applied almost all the solutions, but still I have not succeeded applying it entirely.

So, I am asking this question, because almost all the answers I found are for like 4-5 years ago, and I was wondering if there are better solutions now.

I repeat my question: Is there a better way than those listed to override the whole font family in the whole app to only 1 font? (All the views used in the app)?

Thanks in advance!

Cheers!

-------------Problems Reply------------

The best way is still to put your .ttf or .otf font file in the assets folder. Then derive a custom TextView class and fix its' font once and for all so that you don't have to call setTypeface() everywhere.

That is all.

Custom TextView Java Class

Put this class in com.util package

import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.TextView;

public class CustomTextViewRegular extends TextView {

public CustomTextViewRegular(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(attrs);
}

public CustomTextViewRegular(Context context, AttributeSet attrs) {
super(context, attrs);
init(attrs);

}

public CustomTextViewRegular(Context context) {
super(context);
init(null);
}

private void init(AttributeSet attrs) {
if (attrs != null) {
// Set type face
Typeface myTypeface = Typeface.createFromAsset(getContext()
.getAssets(), "Helvetica_Neue.ttf");
setTypeface(myTypeface);
}
}

}

You must have Helvetica_Neue.ttf in assets folder, you can use other font as well.

How to use in xml

<com.util.CustomTextViewRegular
android:id="@+id/txtCustom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"
android:textColor="#727272"
android:textSize="20dip" />

If you want to change font than you have to just change font type in Java class only.

Done

I have found no work-arounds for setting one font on the app, so I resorted in calling setTypeface() for each view in each of the fragment/activities. Thanks, and I apologize for the long time in which i did not answer! I well deserve the downvotes, hehe.

Cheers everyone! I will pay more attention to asking questions and my behavior towards the users answering them in the future.

Category:android Views:7 Time:2018-10-24

Related post

  • How to apply custom font for the whole app? 2012-11-26

    Possible Duplicate: Android: Want to set custom fonts for whole application not runtime I know there is way of doing it in the following way. But I want to apply the font to the entire application. Is that possible? TextView txt = (TextView) findView

  • How do I set a custom font for the whole application? 2011-09-30

    Is there any way to How to Apply global font [new custom font] to whole application in iphone objective-c. I know that we can use below method to set font for each label [self.titleLabel setFont:[UIFont fontWithName:@"FONOT_NAME" size:FONT_SIZE]]; Bu

  • Change the font of whole Android application through preference of the application 2012-04-03

    In my application, I provide a setting for user to change the font of the whole application. I want when user choose one from the list, the whole application will immediately apply this font. I have search many questions related to this problem but I

  • How to Set a Custom Font in the ActionBar Title? 2011-12-22

    How (if possible) could I set a custom font in a ActionBar title text(only - not the tab text) with a font in my assets folder? I don't want to use the android:logo option. --------------Solutions------------- I agree that this isn't completely suppo

  • Is there a simple way to set a default font for the whole app? 2011-02-28

    I'm developping an app with monotouch and I must provide a way to change the font for the whole application. I know I could just set every of my controls font individually but that sounds like a pita ... Is there some kind of application.defaultFont

  • How to apply custom image to checkbox in android 2011-03-03

    I'm trying to apply custom image to checkbox in android, for this I create an check_custom.xml file in which I define custom image for different states of check box like: <item android:state_checked="true" android:drawable="@drawable/btn_check_on"

  • Changing font inside a rich text box paragraph without changing font of the whole paragraph 2011-05-26

    The problem may seem complicated, but I'll be the clearest possible. I need to be able to change the font everywhere in the text of a RichTextBox. For what I've seen so far, it is only possible to add content with a new font at the end of the paragra

  • Generate a keystore for an Android app in the Export Android Application wizard? 2011-07-11

    I'm trying to export a signed Android application in Eclipse. I think I'm going in the right direction: Right click on project > Android Tools > Export Signed Application Package The Export Android Application wizard appears. Select the project

  • How to change default mouse cursor for the whole WPF application globally? 2011-10-06

    In my WPF application I am using only one mouse cursor. Is there any way to change this cursor for the whole WPF application globally? --------------Solutions------------- The Mouse.OverrideCursor method allows you to set the cursor for the entire ap

  • J2me set font to the whole list 2011-11-29

    There's a method setFont(int listItem, Font font) in List class which sets some font to the list item. So I have to run through the list items and set fonts in a cycle. Is there any method to set one font to the whole list? --------------Solutions---

  • How to install the custom fonts in the computer so that you can use in PowerPoint 2007 2012-05-04

    How to install the custom fonts in the computer so that you can use in PowerPoint 2007? --------------Solutions------------- http://office.microsoft.com/en-us/powerpoint/HA102880841033.aspx Download and install a custom font on a computer running Vis

  • Applying rounded corners for the whole application 2012-01-05

    How can I implement rounded corners applied to the whole view as seen on screenshot (note that both navigation bar and keyboard corners are rounded)? I've tried setting cornerRadius = 10 and masksToBounds = YES for both window.layer and window.rootVi

  • Custom fonts and XML layouts (Android) 2010-03-04

    I'm trying to define a GUI layout using XML files in Android. As far as I can find out, there is no way to specify that your widgets should use a custom font (e.g. one you've placed in assets/font/) in XML files and you can only use the system instal

  • Use Custom debug key to debug android application? 2011-06-13

    I have include Google map view in my android application. When I debug with my computer in office it gives the map in my map view. But when I try to test it at home it did not give any map. I need to know how can I debug with custom debug key so I ca

  • Using a custom font throughout the project 2012-03-30

    I've got a Prism project with a dozen modules in it. I want to use a custom font (a .TTF file, to be specific) in all the modules. When I put the .ttf file in the module folder - it works, but what if I add a dozen more modules? So, I want to have th

  • Question about varrying top margin when using custom Fonts on the iPhone 2010-05-11

    I am using FontLabel to display varying lengths of texts in a custom font. I size the FontLabel using the following : CGSize size = [myString sizeWithFont:[UIFont systemFontOfSize:[[[UIApplication sharedApplication] delegate] getFontSize]] constraine

  • Is it possible to decompile the whole .NET application? 2010-06-23

    I know that .NET apps are difficult to protect. I use RedGate Reflector and know that generally speaking you can get source code from many .NET dlls. however my question is - is it actually feasible to decompile the whole application? I mean - create

  • Displaying custom fonts on the iphone 2010-11-14

    I have a game which I would like the time and score to be displayed in a custom font. How does one display their own fonts, or would I need to write an algorithm which controls a list of number images e.g. 1, 2, 3 etc. and displays them e.g. 134 ----

  • What is the maximum Android Application size? 2011-02-25

    Possible Duplicate: Android - Application (apk) Maximum size I have an app that will have lots of videos. The iPhone version is 1.2GB. I am converting it to Android and would like to know if 1.2GB is too big? Is there an Android like iTunes applicati

  • The whole wpf application is blocked after i call Show() for new window 2011-06-02

    I am developing a WPF-application using mvvm pattern. And a strange problem occurred to me. There is a form, which contains a devexpress DXGrid control. There is a command binded to double click gesture in presenter. When the command triggers a new w

  • Is it possible to set custom ModelBinder for the whole controller? 2011-08-12

    I've a custom model binder and I know two ways of assigning this to my action method: Either at the method: public ActionResult MyAction([ModelBinder(typeof(MyCustomModelBinder))] ModelClass filter Or globally in global.asax.cs: ModelBinders.Binders.

  • How can I view the differences between an Android custom ROM and the official Android source? 2011-12-23

    Having recently acquired an Android device, I started playing around with building a custom ROM image. I downloaded a version of CyanogenMod 7.2 ported for my device and built it successfully. Since this is a port to my device, I'd be interested in c

  • How do I apply a style to the whole row using XLWT Python Excel? 2012-02-23

    I'm trying to apply a style that will highlight the whole row if one of the columns contains the value "Assets". The code below will highlight only the column with "Assets" in it, instead of the entire row. Is there a way to apply the style to the wh

  • How to programmatically apply CSS definitions to the whole page? 2012-04-15

    I'm sure the information already exists, but I couldn't find it; sorry :-/ I want to create CSS rules using JavaScript, and apply them to the whole page, as if they were in a style element in the document's head. I don't want to do it by generating t

  • Automating the testing Android Applications? 2012-04-18

    Hi people I have a serious problem at hand, I need to know about some tool that will automate the black box testing of the Android applications made using HTML, JavaScript , CSS for the native apps I am using Robotium as the testing tool to automate

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.076 (s). 11 q(s)