我的自定义字体不设立在编辑文本 [英] My custom font not setting up in edit text

查看:135
本文介绍了我的自定义字体不设立在编辑文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  mEditText =(EditText上)getContentView()findViewById(R.id.custom_text)。
AssetManager租入资产价值=的getContext()getBaseContext()getAssets()。
字样TF = Typeface.createFromAsset(租入资产价值,字体/ DroidSansFallback.ttf);
mEditText.setTypeface(TF);
 

我想用上面给出的code设置我的自定义字体。一切顺利,没有任何错误,但我不能把我的自定义字体为我的 EDIT_TEXT 。我无法弄清楚发生了什么。

解决方案

  //尝试这种方式,希望这将有助于你...

1.首先,你必须创建字体目录下的资产的目录,并把你的字体目录自定义字体文件。

2.现在尝试应用这一code在这里,我用我的自定义字体黑体LT 45 Light_0.ttf

XML
<的LinearLayout
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    机器人:填充=5DP
    机器人:重力=中心>

    <的EditText
        机器人:ID =@ + ID / edtCusomFonts
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT/>
< / LinearLayout中>

活动
 私人的EditText edtCusomFonts;
    @覆盖
    保护无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);

        edtCusomFonts =(EditText上)findViewById(R.id.edtCusomFonts);
        字样TF = Typeface.createFromAsset(getAssets(),字体/黑体LT 45 Light_0.ttf);
        edtCusomFonts.setTypeface(TF);

    }
 

mEditText = (EditText) getContentView().findViewById( R.id.custom_text );
AssetManager assests=getContext().getBaseContext().getAssets();
Typeface tf = Typeface.createFromAsset(assests, "fonts/DroidSansFallback.ttf");
mEditText.setTypeface(tf);

I am trying to set my custom font using the code given above. Everything goes fine, there is no error, but I am not able to set my custom font to my EDIT_TEXT. I am unable to figure out what is happening.

解决方案

// 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);

    }

这篇关于我的自定义字体不设立在编辑文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆