I want to know if there is a way to set the default phone font to my app. At this point my app reads the font from my LG G2 (purewhite font) and sets it only on dialogs, snackbars and toasts not in textviews or spinners. How can I pass the font to textview and spinners?
Asked
Active
Viewed 458 times
2 Answers
0
There are several ways to do this.
From this answer, you can create custom views such as:
public class YourTextView extends TextView {
public YourTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public YourTextView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public YourTextView(Context context) {
super(context);
init();
}
private void init() {
Typeface tf = Typeface.createFromAsset(context.getAssets(),
"fonts/helveticaneue.ttf");
setTypeface(tf);
}
}
Then you can simply use this textview in your layouts instead. The main benefit is that you don't have to specify fonts for them individually.
If you do want to specify fonts individually then:
TextView tv=(TextView)findViewById(R.id.custom);
Typeface face=Typeface.createFromAsset(getAssets(),"fonts/Verdana.ttf");
tv.setTypeface(face);
If you'd rather use a library, check out Calligraphy, which does all this and more.

Community
- 1
- 1

Aditya Anand
- 776
- 2
- 9
- 29
-
in this way I must declare my own font, I want the app to read the phone's font. – giannisj5 Feb 17 '16 at 09:23
-
@giannisj5 What do you mean by "the phone's font"? "The phone", i.e an untainted android OS has only the one default font family, sans, serif, roboto etc. These are available by default to all apps. If the user has set a custom font using a launcher, for example, then I'm afraid there's no general rule to getting that font. Or perhaps it's vendor specific. – Aditya Anand Feb 18 '16 at 06:00
-
look at my pictures my friend, the dialogs do want i want: sets the default phone font (purewhite.ttf which is in default fonts of LG G2) to their letters, why doesn't the textviews do the same? – giannisj5 Feb 18 '16 at 08:45
0
ok, i found the solution:
i replaced
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
with
<style name="AppTheme" parent="android:Theme.DeviceDefault.NoActionBar">
in my "styles.xml"
and added
app:backgroundTint="@color/colorPrimary"
app:rippleColor="@color/colorPrimary"
in my floating button code (android.support.design.widget.FloatingActionButton)

giannisj5
- 119
- 1
- 11