Attached below is a screenshot of the fonts on my device.
Here is the requirement:
Examples:
(The default font on the system may or may not be Roboto)
How do I programmatically get the font selected on the system, and also know if it's the default one or not?
I know that if I use Typeface.DEFAULT, it would give me the selected font. But I would also like to know if it's the Default font (as seen in the attached screenshot).
You might want to look into this Typeface. This class provides tools so that you can know which font/typeface is selected for against which type.
For e.g. Look at defaultFromStyle
Typeface.defaultFromStyle(int style)
where the value of Style is an Integer and the values varies from
int: Value is NORMAL, BOLD, ITALIC, or BOLD_ITALIC
Edit 1
After doing a bit of research I found that Typeface doesn't provide the font name. Then i found this SO this gives very useful information and it leads to another SO which has a custom FontListProvider and states that the first font will be the default Font. If you use that custom class then it would be very easy to find the default font.
final List<FontListParser.SystemFont> fonts = FontListParser.safelyGetSystemFonts();
String[] items = new String[fonts.size()];
for (int i = 0; i < fonts.size(); i++) {
Log.e("Font",fonts.get(i).name);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With