I am trying to create app which provide text formatting (like font style , font size , font color). So I want default fonts provided by android as a list to be shown in drop-down. Selecting font from drop-down will change the Text dynamically.
Can anyone help , how can I achieve this either via XML or programmatically ?
See the image how it must look like
font list is saved in Typeface class as a static field Map<Stirng, Typeface> sSystemFontMap. you just need to get this field. See my answer here.
There are only three system wide fonts in Android SDK.
normal
serif
monospace
More info : click here
Related
I develop a calculator application and I want customize my EditText like digital number in this picture:
What should I do? Thanks
You would need to find a font matching the one you are looking for (just search for digital font tff files) and apply that font. How to do that can be found here.
You need make the elevation and circle corner of Button,Try Defining Shadows.And also the specific font or image instead to custom the digital number.
I changed the font in my application to a custom font, but I don't know how to change the font in Android Studio in the design view, where you can drag n drop buttons, textviews, etc.... Any ideas? Because of this I can't position correctly the buttons on my layout, because it's different in emulator, and different in design view. Thanks for help!
If you want to use the custom font in android you have to add that font in assets and use it from there. Use these links 1 & 2 hope this can help
You can't set custom font at design view. you set custom font using only java code.
I have several fonts with different styles, lets say: "MyFont_default.otf", "MyFont_italic.otf", "MyFont_bold.otf"
Normally, I would set the font of a TextView like this:
Typeface tf=Typeface.createFromAsset(context.getAssets(), "MyFont_italic.otf");
textView.setTypeface(tf);
And my question is: is it possible to combine all these fonts, into one single font, say "MyFont", and depending of the TextView style defined in the XML layout file (italic, bold), the TextView to be displayed in the appropriate font?
I don't have the proper reputation to comment but I can confirm, that approaches work.
Using FontForge (binary available for Windows):
Open your multiple .otf files with FontForge (Regular, Bold, Italic).
Make sure to select the window showing the "Regular" version of the font
Use File > Save ttc from that window
See that indeed the other sub fonts are listed in the save dialog (bold, italic)
Save and use this ttc file in Android
I tested it with an html text displayed in a TextView :
<b>Test</b> Test <i>Test</i>->
"Test Test Test" which didn't work previously in Android 2.3.7 and with this ttc font all three versions of the text show perfectly.
As I said, it's important to select the Regular font when exporting because that's the one Android uses as "default" (I did an export first from the Bold version and it was all Bold).
Use some sort of font editor to combine the fonts into a single file. Many fonts come with multiple styles in a single file, which is what you would need in this case.
Ok my first question is:
Is there a way to change the font on everything in my app? I mean to put for ex the font x.ttf to be the default font for all the buttons,listviews,for everything that is in my app? And if yes,how?
And my second question:
If that is not possible,then please tell me how to change the font on the Tab widget...
Thanks
Still There is no way to change the font for a complete application. All You can do is for Text Views create custom Text View and override the font method. Then you can use the customized text view rather than using the default text view.
This is the way I used the font Helvetica for My app.
Suppose I have an "apk" file. In this app, we can set the font. My question is how we can set that selected font for all applications.
You can't. What would be the point of me being able to define fonts in my application if you were going to override them?