How to apply custom font for the whole app? [duplicate] - android

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Android: Want to set custom fonts for whole application not runtime
I know there is way of doing it in the following way. But I want to apply the font to the entire application. Is that possible?
TextView txt = (TextView) findViewById(R.id.customfont);
Typeface font = Typeface.createFromAsset(getAssets(), "fonts/Molot.otf");
txt.setTypeface(font);

Its not possible to give one for the entire application however, if you look at the accepted response on:
Android: Want to set custom fonts for whole application not runtime
they have a solution that makes it easier to set it to any view easier :) Another method is creating a custom widget to replace TextView, but if you require the font on other widgets too, it gets quite messy!

Related

TextView: display text in preview only, not during runtime [duplicate]

This question already has answers here:
Can you set graphical layout preview-only text on a TextView?
(2 answers)
Closed 5 years ago.
Is there a way to have text displayed in the preview pane in Android studio but not in the actual app while running on the phone?
I currently use the android:hint attribute, which is quite useful to see how much space a TextView requires or what size the text will be.
The problem, however, is that in case no text is assigned to the TextView, the hint shows in the app.
Is there a way to have the text display only in android studio but not at runtime?
It's tools:text="some text". This only will be visible in Android Studio.
From docs:
You can insert sample data in your layout preview by using the tools: prefix instead of android: with any attribute from the Android framework. This is useful when the attribute's value isn't populated until runtime but you want to see the effect beforehand, in the layout preview.
For example, if the android:text attribute value is set at runtime or you want to see the layout with a value different than the default, you can add tools:text to specify some text for the layout preview only.

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.

Default custom font

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.

Android Font Change

I am trying to create an android app that will change the font at the push of a button. I have searched through stackoverflow and other sites on Google, but have come up empty handed. I am using Eclipse. The goal is to be able to simply touch a button that reads "times new roman" and then have the text above change to that font. I found people trying to change the font in Eclipse, or simply the default font for their app, but not have the user be able to change it. I got this idea after finding an app that changes background colors. Does anyone know what code I need for the buttons?
Typeface is what you are looking for.
In the onclicklistener of the button, try something like
TextView txt=(TextView)findViewById(...);
Typeface tf=Typeface.createFromAsset(...);
txt.setTypeface(tf);

Dual text TextViews on Android [duplicate]

This question already has answers here:
Is it possible to have multiple styles inside a TextView?
(20 answers)
Closed 9 years ago.
I am currently working on android project where I want to have a text view that contains two lines of code. I know I can just put a new line character in between to make it on a new line but I want to do a bit more than that.
Basically what I want achieve is on the first line I have text which uses the normal text design and on the next line the text will be styled differently, i.e. smaller and slightly different font colour.
I've tried searching for this and can't find anything anywhere.
Thanks for any help you can provide.
Option #1: Just use two TextView widgets in a vertical LinearLayout
Option #2: Use Html.fromHtml() to convert an HTML representation of what you want into a Spanned object that you can pass to setText()

Categories

Resources