Sans-serif-light with fake bold
I installed the following theme for my application:
<style name="AppTheme" parent="Theme.Sherlock.Light">
<item name="android:textViewStyle">@style/RobotoTextViewStyle</item>
</style>
<style name="RobotoTextViewStyle" parent="android:Widget.TextView">
<item name="android:fontFamily">sans-serif-light</item>
</style>
So when I create TextView, I get the "roboto light" font that I want. Some TextView, however, I would like to set the attribute textStyle="bold", but it does not work, since a light font does not have a "native" (?) Bold version.
On the other hand, if I programmatically use the method setTypeface, I could get bold:
textView.setTypeface(textView.getTypeface(), Typeface.BOLD);
This font is obtained from the light of robotography and looks really good.
I would like to have this bold , but I wonder what the most elegant way to do this.
Is it possible to do this only with xml?
What is the best implementation if I need to create a "
BoldTextView extends TextView"?
+4
1
:
public class FakeBoldTextView extends TextView {
public FakeBoldTextView(Context context) {
super(context);
setTypeface(getTypeface(), Typeface.BOLD);
}
public FakeBoldTextView(Context context, AttributeSet attrs) {
super(context, attrs);
setTypeface(getTypeface(), Typeface.BOLD);
}
public FakeBoldTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setTypeface(getTypeface(), Typeface.BOLD);
}
}
XML, :
<the.package.name.FakeBoldTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Example string" />
+2