How to get font which is currently used in textview/edittext? I don't set custom font but need to know which font android uses to show me the text in textview: Noto, Roboto, Noto CJK or SansSerif Hebrew and etc.
Asked
Active
Viewed 3,266 times
2
-
getTypeface() will help you. – droidd Feb 10 '15 at 06:07
-
I tried it and received null. – Access Denied Feb 10 '15 at 06:12
2 Answers
1
There is nothing wrong with your question.
If you have not used setTypeFace()
you will recive null
the default TypeFace for a TextView
or Button
is defined in the style.xml
.
Something like:
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:textViewStyle">@style/RobotoTextViewStyle</item>
<item name="android:buttonStyle">@style/RobotoButtonStyle</item>
</style>
<style name="RobotoTextViewStyle" parent="android:Widget.TextView">
<item name="android:fontFamily">sans-serif-light</item>
</style>
Check this questions Default Font-Family for App , Default font
I tried it myself and you are right, it returns null
seems like typeFace change the default attributes but the attriburtes wich the view is started with are not directly interpreted as a typeFace

Vadim Kotov
- 8,084
- 8
- 48
- 62

UrielUVD
- 482
- 1
- 9
- 27
-1
Have you tried calling getTypeface()
in your TextView
before you change it and store the result somewhere?
Check this link, this will help you

iOSNoob
- 1,420
- 2
- 16
- 30
-
I used default hello world sample. I get TextView through findView by id and call getTypeface from textview. That's it. – Access Denied Feb 10 '15 at 06:19
-
Have you checked the link mate. It contains one property for getTypeface(). i.e fontFamily. Take a look at it. – iOSNoob Feb 10 '15 at 06:23
-
I've looked at your link. It doesn't make sense to me: textView = (TextView) findViewById(R.id.textView); Typeface typeface = textView.getTypeface();<- this is null – Access Denied Feb 10 '15 at 06:27
-
2Let me know how to get Font Family name (String) from typeface. Typeface doesn't have fontFamily member. – Access Denied Feb 10 '15 at 09:43