Im working on my first Android application bigger than one activity.
I've read this:
Android 4.1 adds several more variants of the Roboto font style for a
total of 10 variants, and they're all usable by apps. Your apps now
have access to the full set of both light and condensed variants.
(here: link)
I also read somewhere, that I can use custom TTF font.
Does it mean, that Android API below 4.1 (API 16) cannot support custom fonts?
Do I have to work on API 16 or above? I have 4.0.4 phone for now, I don't want to throw it away yet...
Don't throw away your phone! You certainly can use custom fonts below API level 16.
First add your font (ttf file) to your /assets folder, then do something like:
Typeface typeface = Typeface.createFromAsset(getAssets(), "myfont.ttf");
myTextView.setTypeface(typeface);
http://developer.android.com/reference/android/widget/TextView.html#setTypeface(android.graphics.Typeface)
It has been around since API level 1.
The fonts in your question can be used without having to include any font file - they are not "custom" but built into the platform and available for all to use.
Related
I'm trying to create an app in a different language (in particular Tamil). I've just used Tamil text in the places where I'd use strings and the text renders correctly for newer device simulators (I've tested on API 16 and above). However, when I try running on a simulator with API 10, then I just get rectangles in place of characters. How can I get the text to render correctly on these older devices too?
Did you put it in correct res folder? If your app is supporting multiple language, you must have multiple 'values-xx' in your res folder. For example, if your app supports telugu, you need to create 'values-te' folder with strings.xml inside that folder and put your tamil translation in that file. And you also need to have proper font to render. You can check on your device settings > languages and input > language. See if there any preferred language that you're looking for. If not, you need to provide your own fonts in your app.
You can refer your issue here, and also Android Documentation on how to properly handle multiple languages.
In my application i want to use marathi font.I know how to use custom fonts in android.The problem is that when i use "Kruti Dev" it shows in android studio preview emulator even thought i have not set it.But if i try to use "Subak" font i am not getting the desired output.
So please can you tell me how will i be able to use this font.
Custom Font Code
Typeface face=Typeface.createFromAsset(getAssets(),
"fonts/subak.ttf);
There is an issue in Android 5.0 that causes some custom fonts to not render when loaded via the Typeface.createFromAsset() function.
The workaround is to re-encode the font that is not displaying. Upload the font file to http://www.freefontconverter.com/ and convert it to output as a TTF. Place the outputted file back in your assets folder and it should now display correctly on Android.
This issue was fixed in the Android 5.1 release.
Reference:
https://androidbycode.wordpress.com/2015/06/02/help-my-custom-font-does-not-work-on-android-5-0/
I am working on an Android Application on Corona Sdk.
and I am using chinacat font for it.
The Problem is the font is being displayed correctly in simulator,
but when i deploy on device it is displayed in normal font.
I am on Windows 8.1.
Here is my code:
local fontname="chinacat"
texts = display.newText(word, 0, 0, fontname, fontsize)
~Thanks
Using Custom Fonts can be tricky at first, specially regarding what name to use as the font filename as well as inside the code.
Just follow the guide below and you will be fine.
http://www.coronalabs.com/blog/2013/01/16/faq-wednesday-custom-fonts/
Just put it in the root folder of your project. And make sure that the font supports from a-z,A-z,0-9 if the font doesn't support it, your app will use the native font
In our application, we're using Roboto and Roboto Bold. However, in some versions of Android (seems to be 4.0 to 4.1) we have issues with text rendering when using the imported version of Roboto (i.e. using Typeface.createFromAsset()) that do not appear when simply using the built-in version of Roboto (i.e. Typeface.DEFAULT).
I know that Roboto and Roboto Bold were introduced in Android 4.0, but I can't seem to find anything that guarantees that these fonts are available regardless of manufacturer modification (e.g. Touchwiz, Sense). If they are guaranteed to exist, we can just use a version check to only use the custom import for devices lower than Android 4.0.
EDIT: With some experimentation, particularly with the Galaxy S3 that allows a user to change their font, this is what I've discovered:
Using Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL) will return that CUSTOM typeface, rather than the system default sans-serif font (i.e. Roboto)
Instead, use Typeface.create("sans-serif", Typeface.NORMAL) (or BOLD) and it will return Roboto regardless of the user's font customization. From the list below, you can actually use "helvetica", "tahoma", "verdana", or "arial" above instead of "sans-serif" with the same result.
I found a document called system_fonts.xml that seems to confirm that Roboto will be used for any reference to Typeface.SANS_SERIF in the SDK directory under:
platforms > android-14 > data > fonts
<!--
System Fonts
This file lists the font families that will be used by default for all supported glyphs.
Each entry consists of a family, various names that are supported by that family, and
up to four font files. The font files are listed in the order of the styles which they
support: regular, bold, italic and bold-italic. If less than four styles are listed, then
the styles with no associated font file will be supported by the other font files listed.
The first family is also the default font, which handles font request that have not specified
specific font names.
Any glyph that is not handled by the system fonts will cause a search of the fallback fonts.
The default fallback fonts are specified in the file /system/etc/fallback_fonts.xml, and there
is an optional file which may be supplied by vendors to specify other fallback fonts to use
in /vendor/etc/fallback_fonts.xml.
-->
<familyset>
<family>
<nameset>
<name>sans-serif</name>
<name>arial</name>
<name>helvetica</name>
<name>tahoma</name>
<name>verdana</name>
</nameset>
<fileset>
<file>Roboto-Regular.ttf</file>
<file>Roboto-Bold.ttf</file>
<file>Roboto-Italic.ttf</file>
<file>Roboto-BoldItalic.ttf</file>
</fileset>
</family>
Since the vendor fonts must be placed in fallback_fonts.xml and the system fonts will always be prioritized, and the first family listed is Roboto under the aliases of sans-serif, aria, helvetica, tahoma, or verdana, unless I find out otherwise I think it's safe to assume that Roboto will be the font returned for a call to Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL).
I'm still going to leave this open for now, hoping for a definitive answer, as I'm unsure whether an OEM is allowed to modify system_fonts.xml. If they are, then this isn't really helpful at all.
In Section 3.8.5 of the Android 4.0 Compatibility Documentation it says:
3.8.5. Themes Android provides "themes" as a mechanism for applications to apply styles across an entire Activity or application.
Android 3.0 introduced a new "Holo" or "holographic" theme as a set of
defined styles for application developers to use if they want to match
the Holo theme look and feel as defined by the Android SDK [Resources,
24]. Device implementations MUST NOT alter any of the Holo theme
attributes exposed to applications [Resources, 25]. Android 4.0
introduces a new "Device Default" theme as a set of defined styles for
application developers to use if they want to match the look and feel
of the device theme as defined by the device implementer. Device
implementations MAY modify the DeviceDefault theme attributes exposed
to applications [Resources, 25].
AFAIK, the Roboto font set is part of the holo theme, and therefore is required to be present on any Android 4.0 and above device that has been certified by Google (i.e. runs Google Play).
The same requirement is also present in the 4.1 and 4.2 documents
(Search for Holo in the PDFs to find the section quickly. There's only 4 mentions of it)
I realised recently that the Android Browser doesn't have any of the fonts I have in my font stack as a Times Replacement with the help from http://www.codestyle.org/css/font-family/index.shtml.
"Times New Roman",Times,FreeSerif,"DejaVu Serif",serif
I'm not angry about it, because it looks nice. But I want to know what is the font's name so that I can include it into my font stack.
You don’t need to add a name, since the Android browser checks your current list, notices that none of the specific names matches, and uses serif, which is mapped to the browser’s serif font. Similarly for the Android sans-serif font (which is what your heading refers to...), use just the generic name sans-serif.
Oddly enough, the often-advertised name Droid Serif does not work. It is just yet another unrecognized name to the Android browser. See e.g. the question Using CSS font-family to select Droid fonts not working on Android (the question is more useful than the comments and answers).
The original Android font was "Droid" (Serif version is "Droid Serif"): http://en.wikipedia.org/wiki/Droid_(font)
The font in the newer devices is "Roboto", though I'm not sure if it has a serif version.