question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support default font for bold/italic style?

See original GitHub issue

I don’t know if this feature has been implemented or not. I just recently applying OpenSans-Regular.ttf as global default, then all bold TextView turned to normal (non-bold style). I wish there is a built-in and clean way to provide default bold font file (e.g. OpenSans-Bold.ttf) when used by TextView, perhaps by checking it in TextView#getTypeface().isBold().

I think this feature will come in handy because it will eliminate the need to apply custom style one by one to all bold/italic texts.

Thanks

Issue Analytics

  • State:open
  • Created 9 years ago
  • Comments:20 (7 by maintainers)

github_iconTop GitHub Comments

14reactions
chrisjenxcommented, Aug 8, 2014

@akhyrul Yes I have been researching how to do this. I expect this will be a 2.x feature.

For example you would define:

fonts/
  OpenSans-Regular.ttf
  OpenSans-Bold.ttf
  OpenSans-Italic.ttf

Which would scope to something like:

<TextView
  fontPath="fonts/OpenSans-*" 
  textStyle="bold"/>

Which would inherently lookup OpenSans-Bold if it can’t find it then apply fake bold etc.

This would also be applicable to strings <string>Hello <b>World</b></string> which would try to find the correct bold version instead of applying fake bold.

This is what you’re thinking right?

9reactions
akhycommented, Sep 4, 2014

@OneManMobile rather than manual search-and-replace, currently I’m using this cleaner temporary workaround by using styles:

<!-- styles.xml -->
<style name="AppTheme.TextAppearance" parent="android:TextAppearance">
        <item name="fontPath">fonts/OpenSans-Regular.ttf</item>
</style>
<style name="AppTheme.TextAppearance.Bold" parent="AppTheme.TextAppearance">
        <item name="fontPath">fonts/OpenSans-Bold.ttf</item>
        <item name="android:textStyle">bold</item>
</style>

So I can use it in any layouts like this:

<TextView
    style="@style/WhateverStyle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/title"
    android:textAppearance="@style/AppTheme.TextAppearance.Bold"/>

I purposely put <item name="android:textStyle">bold</item> to make sure preview in Android Studio shows correct bold style.

Hopefully there will be a cleaner way in 2.x 👍

Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

font-style - CSS: Cascading Style Sheets - MDN Web Docs
The font-style CSS property sets whether a font should be styled with a normal, italic, or oblique face from its font-family.
Read more >
Add bold, italic, underline, and strikethrough to text in Pages ...
The Style controls in the Format sidebar with callouts to the Bold, Italic, Underline. Click one or more format buttons in the Font...
Read more >
Fonts and Formatting for Visual Studio - Microsoft Learn
By default, the environment font is tied to a system font that appears as 9 pt Segoe UI in current versions of Windows....
Read more >
How To Style Text Elements with Font, Size, and Color in CSS
Save styles.css , then open up index.html in your browser. You will find a new font in place of the browser default font...
Read more >
Font families and font styles - JpGraph
Font family name Type Comment FF_FONT0 Bitmap A very small font FF_FONT1 Bitmap A medium sized font FF_FONT2 Bitmap The largest bit mapped font
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found