Roboto font for Android 4+? - android

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.

Related

Android Monospace doesn't behave as a fixed-pitch

As you can see in the screenshot below the two different strings with the same length not drawn with the same width on the canvas. I'm using a monospaced typeface, so isn't it promised to be drawn with the same width? Is that because of the kerning?
Typeface.create(Typeface.MONOSPACE,Typeface.NORMAL)
This is a well-known kerning issue with monosapce font on Android. It looks like this is a quite old topic.
Some people have already faced this problem:
Android Monospace fonts aren't fixed width - 2013-06-11
Are Android monospace fonts actually fixed size? - 2016-06-22
Android monospace space ( ) width is different than character width - 2017-03-02
The issue also occurred in mobile web environment:
Font monospace Android 2.3 - 2013-07-11
where problem explained with missing glyph:
https://github.com/googlefonts/noto-fonts/issues/617
Solutions:
Option 1.:
Looking for an alternative fixed-width font might be the easiest way. Some helpful links to find one:
https://1stwebdesigner.com/free-monospaced-fonts/
https://www.fontsquirrel.com/ https://www.dafont.com/
https://www.urbanfonts.com/free-fonts.htm
https://www.1001freefonts.com/
Option 2.:
You can override text drawing using Spans. This post may help you:
https://stackoverflow.com/a/53452941/5823014
Option 3.:
You can modify the monospace font file to fix kerning. This online tool can be useful:
http://www.glyphrstudio.com/online/

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

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.

What is the font in Android's ActionBar?

What font is used by default, in the holo Android ActionBar?
I've only been able to find answers on how to change the font, but not what the default font is.
Thanks.
On API Level 14+, the default font face for everything is Roboto. On API Level 13 and below, the default font face for everything is Droid Sans.
Conceivably, that could be changed by device manufacturers, though.
If you don't set any font programmatically then it will consider your device's font settings and set that for your actionbar.

Honeycomb makes texts pixelized

My app looks fine on my Galaxy S, but when I run it on a Galaxy Tab 10.1 (Android 3.0), the texts look pixelized/smeared:
The XML used for the Synchronize button follows:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/synchronizeButton"
android:background="#drawable/button"
android:text="Synchronize"
android:textSize="20dp"
android:textColor="#drawable/buttoncolors"
android:layout_marginBottom="10dp"/>
Is there something wrong I am doing, or is there something special I need to do to make my apps Honeycomb-compatible?
Is your application running in compatibility mode? If so, this is expected. You need to indicate in your manifest that you support large screens.
Try changing textSize="20dp" to textSize="20sp". When dealing with text you should always use "sp" (scale-independent pixel). Hopefully this fixes it.
see this page for more info: http://developer.android.com/guide/practices/screens_support.html

How to display icons without alteration in an ImageButton/ImageView?

in my app, I have buttons with icons. The icons are provided as PNG images in the three densities in drawable-ldpi-v4/, drawable/ and drawable-hdpi-v4/. Here's a sample:
Each icon is displayed in an ImageButton:
<ImageButton style="#style/Shortcut" android:id="#+id/open_button"
android:src="#drawable/shortcut_open" android:layout_marginRight="4dp"/>
Where the Shortcut style is:
<style name="Shortcut">
<item name="android:layout_width">65dp</item>
<item name="android:layout_height">45dp</item>
<item name="android:scaleType">center</item>
<item name="android:background">#drawable/shortcut_background</item>
</style>
However, on certain devices/platform versions, certain icons get altered, blurred or something. I'm not sure that it's scaling, it's more like a rendering bug I think. I have tried to disable anti aliasing on the BitmapDrawable, but that didn't help.
As shown on the image below, on Android 2.1 LDPI, one icon gets broken/cropped, and on both Android 1.6 MDPI and Android 2.1 HDPI an extra line seems to be randomly added at the bottom of the icon (look closely).
In the manifest, I have an empty <supports-screens /> as recommended in the docs about supporting multiple screens in legacy apps. Adding anyDensity="true" doesn't help.
Apparently, as of Froyo, things get better as you can see on the image above. But how can I solve this on Android <= 2.1?
I think you should not use explicit sizes (even when expressed as dip) for the buttons, but let the system do it for you.
Use
<ImageButton android:id="#+id/SpeakButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Also it may be that you are falling into the "dip" vs. "dp" trap that others have reported, where documentation says that they are synonymous, but using "dip" made stuff work as intended.
Not sure if this is the case but you can check if you are not running into the bugs mentioned in this Google I/O talk. I still have to wrap my head around it but I think it's worth having a look if you are targeting platforms from 1.5 to 2.0.

Categories

Resources