mEditText = (EditText) getContentView().findViewById( R.id.custom_text );
AssetManager assests=getContext().getBaseContext().getAssets();
Typeface tf = Typeface.createFromAsset(assests, "fonts/DroidSansFallback.ttf");
mEditText.setTypeface(tf);
我正在尝试使用上面给出的代码设置我的自定义字体。一切顺利,没有错误,但我无法将自定义字体设置为EDIT_TEXT
。我无法弄清楚发生了什么。
答案 0 :(得分:1)
// try this way,hope this will help you...
1. First of all you have create "fonts" directory under "assets" directory and put you custom fonts file on "fonts" directory.
2. now try to apply this code here i used my custom fonts "Helvetica LT 45 Light_0.ttf"
XML
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:gravity="center">
<EditText
android:id="@+id/edtCusomFonts"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Activity
private EditText edtCusomFonts;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edtCusomFonts = (EditText) findViewById(R.id.edtCusomFonts);
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/Helvetica LT 45 Light_0.ttf");
edtCusomFonts.setTypeface(tf);
}
答案 1 :(得分:0)
尝试
mEditText.setTypeface(Typeface.createFromAsset(context.getAssets(),"fonts/DroidSansFallback.ttf"));