How do I access DroidSans.ttf directly from the android sdk? - android

I'm trying to do this
The important part of that code is here:
Notice this line of code where "fontAssetName" would be some font file (in my case it's DroidSans.ttf) which has to be in my assets folder.
final Typeface regular = Typeface.createFromAsset(context.getAssets(),
fontAssetName);
I want to do it without having to have a copy of ttf font file in my assets folder. This is because I don't want to have to deal with the copyright license of downloading a font. The font I want to use is DroidSans.ttf which should be provided in the android sdk as it is the default font. Is there any way I can access this font from the android sdk?

Android has built in fonts,
android:fontFamily="sans-serif" // roboto regular
android:fontFamily="sans-serif-light" // roboto light
android:fontFamily="sans-serif-condensed" // roboto condensed
android:fontFamily="sans-serif-thin" // roboto thin (android 4.2)
android:fontFamily="sans-serif-medium" // roboto medium (android 5.0)
If you want to use something different, you need to include the font yourself as you were doing.
Android doesn't include a ton of fonts like a desktop OS. The reason is that it bloats the distribution and creates a non-homogeneous look across apps.

Related

SansSerif FontFamily in jetpack compose

android:fontFamily="sans-serif" // roboto regular
android:fontFamily="sans-serif-light" // roboto light
android:fontFamily="sans-serif-condensed" // roboto condensed
android:fontFamily="sans-serif-thin" // roboto thin (android 4.2)
android:fontFamily="sans-serif-medium" // roboto medium (android 5.0)
Is FontFamily.SansSerif same as Roboto font in Jetpack Compose also?
The short answer is yes, referencing sans-serif is using Roboto, for Compose as well as for the old View-based UI system in Android.
In the context of Compose, it's important to understand that this is only true now and for Android.
Roboto is a sans-serif typeface, and by referencing sans-serif you're really referring to the current sans-serif type the system you're working on uses. It could potentially change in the future. And it could be different if you're running the code in web or desktop (e.g. Helvetica).

Android Studio 2.1.x Printing default font name

I would like to print some code files with Android Studio.
Before I've changed the font Name in the print file Dialog.
But the different font did not fit my needs.
What is the Default font name for printing?
Or what font name do you prefer for printing code on paper?
There are two fonts I really like for code:
Deja Vu Sans Mono which you can download for free here --> http://dejavu-fonts.org/wiki/Download
Source Code Pro which you can download for free here --> https://www.fontsquirrel.com/fonts/source-code-pro
You may also want to check out this top 10 list of free code fonts: http://hivelogic.com/articles/top-10-programming-fonts/
Now, for the default Android Studio font:
I believe it is 'Monospaced'

What Chinese font should i use in my CSS for Android 4.4?

I am using below CSS in my code. But I'm not sure if Android 4.4 have "Microsoft Yahei" font. Which exact chinese font should i specify in my CSS?
body {
font-family: Roboto,Arial,Helvetica,"Microsoft yahei","微软雅黑","微軟正黑體Microsoft JhengHei","微軟正黑體 Microsoft JhengHei","Microsoft JhengHei","微軟正黑體",sans-serif;
}
I believe its Noto Sans but for future reference font are stored under /system/fonts in your android directory if you need to look it up.

Roboto font for Android 4+?

Do I need to use Roboto font and put it to asset folder if my app will support only Android 4+ devices?
I would greatly appreciate for your help. Alex. P.S. Sorry for my English:)
You can use Roboto natively from Android 4.1+ like this:
android:fontFamily="sans-serif" // roboto regular
android:fontFamily="sans-serif-light" // roboto light
android:fontFamily="sans-serif-condensed" // roboto condensed
For any version below that, you have to load the font yourself. Look at this answer I gave a while back for more information.
Answer
Ok. I think, I got it.
Samsung phones are by far the most popular Android phones. Whilst it's
true that all Samsung phones from 4.1 and up have Roboto, they also
have something called Samsung Sans, and if your user has set it as
their default font then the android:font-family (as #Ahmad says)
requests all return Samsung Sans, not Roboto. If you have fixed tight
layouts with no wriggle-room that can't stretch, Samsung Sans will
break them. There's no easy way round this. If you absolutely have to
have Roboto, you must package it as an asset and set it as the
typeface explicitly.
Thx to #Ahmad as well as #Kenton Price's comment here: https://stackoverflow.com/a/14633032/2553905
To add to Ahmad's excellent answer, you can swap out 'light' or 'condensed' to whichever style it is you want from the list in the Material Design guidelines here:
http://www.google.com/design/spec/style/typography.html#typography-roboto-noto
For example:
android:fontFamily="sans-serif-medium" // roboto medium
And so on.
This comment adds no more than Ahmad's, but just clears up that you are not limited to the 3 examples he gave, you can use any.
From documentation:
Ice Cream Sandwich introduced a new type family named Roboto, created
specifically for the requirements of UI and high-resolution screens.
Read more about Typography.

Do we have to copy Font TTF everytime we want to change font in application

Previously, to make my app workable in Gingerbread device and above, I have to copy the Robotto font resource into asset folder. This is because Gingerbread doesn't come with Robotto font itself.
However, let say, I decide to deploy my app to Jelly Bean device only.
Do I still need to copy font resources into my asset folder manually? Can I use font resources from system itself? Is it something encourage-able? I was thinking, without supplying my own font files, I can make my app smaller.
This is the code to get TypeFace from asset folder.
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Regular.ttf");
If I want to get TypeFace directly from system itself, how?
The good news is, if you're supporting 4.1, it's dead simple. Check out this link and scroll down to fonts for the full details, but basically, you'll have three font families (Roboto, Roboto Light, RobotoCondensed) to choose from, and four styles for each (normal, bold, italic, bold italic).
In XML, you can just use the standard text attributes:
android:fontFamily="sans-serif"
android:fontFamily="sans-serif-light"
android:fontFamily="sans-serif-condensed"
android:textStyle="bold"
android:textStyle="italic"
android:textStyle="bold|italic"
Or programatically you can acquire them like so:
Typeface robotoLightItalic = Typeface.create("sans-serif-light", Typeface.ITALIC);

Categories

Resources