Text (font) looks faded with older apis

I use a custom font, and it perfectly displays the new versions of Android (tested on API 17 (Asus tab), 18 (Dell tab), 19 (Nex4) devices). However, the same font looks faded (maybe distorted?) In older versions - API 8 (SE X10i), 10 (LG P500H).

Here's a comparison, if my explanation doesn't make sense:

In nex4:

enter image description here

In x10i:

enter image description here

I am using a custom font with Typeface.BOLD:

tvTitle.setTypeface(titleAndBodyFont, Typeface.BOLD); 

And the body (part of "Looks *"):

 tvBody.setTypeface(titleAndBodyFont); 

XML declaration for the header:

 <TextView android:id="@+id/tvTitle" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="@dimen/margin_title_side" android:layout_marginRight="@dimen/margin_title_side" android:layout_marginTop="@dimen/margin_title_top" android:ellipsize="end" android:maxLines="1" android:textColor="@color/constant_color" android:textSize="@dimen/text_size_title" /> 

tvBody declared in the same way.

Is this a known bug? If so, can someone help me find a bug report? This will help to know which version has been fixed. If not, I would appreciate a decision.

Thanks to everyone.

+6
source share
2 answers

I always use 2 fonts, 1 normal and 1 bold. Therefore, when you need to boldly, just change your font. There has never been a problem, you can also create your own text screen.

Something like that:

/res/values/attrs.xml

 <resources> <attr name="fontFamily" format="enum"> <enum name="helvetica" value="0"/> <enum name="helvetica_bold" value="1"/> </attr> 

your TextViewPlus:

 public class TextViewPlus extends TextView{ private static final String TAG = "TextViewPlus"; public TextViewPlus(Context context) { super(context); } public TextViewPlus(Context context, AttributeSet attrs) { super(context, attrs); setCustomFont(context, attrs); } public TextViewPlus(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setCustomFont(context, attrs); } private void setCustomFont(Context ctx, AttributeSet attrs) { TypedArray a = ctx.obtainStyledAttributes(attrs, R.styleable.TextViewPlus); int customFont = a.getInt(R.styleable.TextViewPlus_fontFamily, -1); setCustomFont(ctx, customFont); a.recycle(); } public boolean setCustomFont(Context ctx, int font) { Typeface tf = null; try { tf = Typefaces.get(ctx, font); } catch (Exception e) { Log.e(TAG, "Could not get typeface: "+e.getMessage()); return false; } setTypeface(tf); return true; } public boolean setCustomFont(Context ctx, String asset) { Typeface tf = null; try { tf = Typefaces.get(ctx, asset); } catch (Exception e) { Log.e(TAG, "Could not get typeface: "+e.getMessage()); return false; } setTypeface(tf); return true; } 

}

How to use:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res/com.myapp" android:layout_width="match_parent" android:layout_height="wrap_content" > <com.myapp.viewhelpers.TextViewPlus app:fontFamily="helvetica" android:layout_width="wrap_content" android:layout_height="wrap_content" app:fontFamily="helvetica" android:text="helo world"/> 

+2
source

I really can't help you, it definitely looks like an error, but to check the extension of the error, you may find this test useful:

  public class TestBoldText extends View { private TextPaint mPaint; public TestBoldText(Context context, AttributeSet attrs) { super(context, attrs); mPaint = new TextPaint(); mPaint.setAntiAlias(true); mPaint.setFakeBoldText(true); mPaint.setFlags(mPaint.getFlags()|Paint.SUBPIXEL_TEXT_FLAG); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawText("i am a bold text!", 0, 0, mPaint) } } 

Android seems to be using a “fake bold” approach to highlight bold text, not a specific bold version of the font. I suppose they draw the same text with pixel offsets. This test prints acceptable bold text to my devices with API> = ICS (samsung galaxy / amazon kindle), but I would be interested to know if it will work on your device, since I am making it look like a wysiwig editor.

In addition, mPaint.setStrokeWidth should change the width of the line of text. I believe that playing with setStrokeWidth / setAntiAlias ​​/ setFakeBoldText you can get decent bold text in an older API, but I am also wondering why the result is not the same ...

good luck with your research!

+1
source

All Articles