Default custom font - android

Is it possible to set a custom font as default in a android application? Because typing this for every TextView is not efficient.
login = (TextView)findViewById(R.id.tvLogin);
login.setTypeface(titleFont);

Is it possible to set a custom font as default in a android application?
Not for a custom Typeface that you loaded from your own font file, sorry. As others have noted, there are workarounds and libraries to help simplify matters a bit. Personally, I'd look at Calligraphy or perhaps Fontify.

Related

Android: using custom font as fallback font for missing glyph

is there anyway to set custom font as a fallback font to the default font?
I need to display some cjk characters not supported by android's default font (which I think is noto font for non latin characters). I have a custom font consists of the glyphs missing, so I'm thinking to use noto as the main font, and set my custom font as fallback.
The only way I can come up with is to make noto font as a typeface and set my custom font as fallback. Then I can assign this typeface to where I need it.
However, this mean I need to programmatically assign almost all textview in the app, which doesn't seem right... (and elegant😅)
I would like to ask what is the best practice for this scenario? Like, perhaps there's a way to declare them as a font family in XML?
Thanks a lot ;)
Let me answer myself :)
After trying, I think the easiest way is to merge two font files together.
Just make sure the font's license allows you to do so.

Android - What is the best way to use a custom font application wide

I want to use Google's Raleway font in my android app. I have read a lot of blogs and a number of answers on stackOverflow but haven't found the exact answer.
The best answer i found is here that explains to create custom TextViews efficiently.
If i have two use two variations of the font say Raleway-Regular and Raleway-SemiBold, do i have to create two custom TextViews or is there any better way to achieve that ?
I have done the task the following way
Download the ttf of that font and then paste it inside the asset folder(you have to create the assets folder inside /src/main/assets)
then change the font the following way:
Typeface face = Typeface.createFromAsset(getAssets(), "condenced.ttf");
tv_the.setTypeface(face);
you can download the multiple ttf files and can display the different fonts to different fields.
Hope this helps.
I am using Calligraphy library for my project and it works perfect.
For me the best way to use a custom font is this library:
Calligraphy

Using Custom Typeface for a TextView in Android Studio Edit Mode

I know we can use Textview.setTypeface to set a custom typeface (ttf file from assets folder) on a Textview programmatically but i wanted to know is there any way to take advantage of this feature in Android Studio's Edit Mode when we're developing the UI with XML ?
I tried to extend Textview class and setting the custom typeface in constructor but the result in edit mode was the same.
It's working perfect when you're running the app on a real device but it gives a better experience to developer when he is developing the layout and see the exact result at the same time.
i wanted to know is there any way to take advantage of this feature in Android Studio's Edit Mode when we're developing the UI with XML ?
Not in standard Android, as there is no XML attribute for associating an arbitrary Typeface. You can use a third-party library like Calligraphy that offers this.
setting the custom typeface in constructor but the result in edit mode was the same
The editor does not necessarily have access to the typeface and so therefore will not show it in the preview. Now, in theory, a custom widget could do something in isInEditMode() and attempt to handle this, but I have no idea how practical that would be.
Custom typefaces are not supported by the layout rendering library currently. You can star the issue to be notified of updates.
http://b.android.com/27321
There are many ways to use typeface correctly in android, you have to put your typeface file in assets folder under your main directly and can use it run-time.
Other simplest way is use default library to set typeface in your xml file. I have prefer this custom typeface library to set typeface to TextView, EditText, Button, CheckBox, RadioButton and AutoCompleteTextView and other wedget in android.
link: https://github.com/jaydipumaretiya/CustomTypeface/
I have found step by step information with images and code to use my typeface in android project.

Supporting custom text weight in Android

Is there a way to support more than standard three available text weights in Android. I need to have five: ExtraLight, Light, Normal, Medium and Bold.
I saw this question: How to change fontFamily of TextView in Android, but it related to family rather than weight.
If there is no in-build support, maybe any external resources or libraries are available?
As I am not aware of how a library could add support for your font without including it, I would advise you to create your own implementation of TextView to handle that, it can be done quite quickly, if you only need it for TextView (you would need to implement your own EditText as well if you need that widget).
You can start by looking at the RobotoTextView library which allows for the RobotoTextView widgets to be used in code as well as directly in xml, using attributes.

how to set the DEFAULT system font in android app?

Can I set the default font which is bydefault set in android app irrespective of which font user has selected???
Thanks in advance
As a developer there is no easy way to use a specific font in every screen of your app.
You have to set your custom font on each and every UI element. This is explained here.
Alternatively you can use this CustomFont helper class to change every UI elemnt for you.

Categories

Resources