use*_*740 6 android textview android-typeface
我正在使用自定义字体,它在新的Android版本上完美显示(在API 17(华硕标签),18(戴尔标签),19(Nex4) - 设备上测试).但是,旧版本的相同字体看起来褪色(可能是扭曲的?) - API 8(SE X10i),10(LG P500H).
这是一个比较,以防我的解释没有意义:
在nex4上:

在x10i上:

我使用Typeface.BOLD的自定义字体:
tvTitle.setTypeface(titleAndBodyFont, Typeface.BOLD);
Run Code Online (Sandbox Code Playgroud)
和身体("看起来*"部分):
tvBody.setTypeface(titleAndBodyFont);
Run Code Online (Sandbox Code Playgroud)
标题的XML声明:
<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" />
Run Code Online (Sandbox Code Playgroud)
tvBody 以类似的方式宣布.
这是一个已知的错误?如果是这样,有人可以帮我找到错误报告吗?这将有助于了解这个版本的修复版本.如果没有,我会很感激解决方案.
感谢大家.
我总是使用两种字体,一种是普通字体,一种是粗体字体。因此,当您需要加粗时,只需更改字体即可。从来没有遇到过问题,您还可以创建自定义 textviewplus。
像这样的东西:
/res/values/attrs.xml
<resources>
<attr name="fontFamily" format="enum">
<enum name="helvetica" value="0"/>
<enum name="helvetica_bold" value="1"/>
</attr>
Run Code Online (Sandbox Code Playgroud)
你的 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;
}
Run Code Online (Sandbox Code Playgroud)
}
如何使用:
<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"/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
493 次 |
| 最近记录: |