1

F1!我正在处理 android 应用程序的另一项活动,在此活动中,我在 8 个乌尔都语文本视图中应用了自定义字体,但显示此活动需要 12 到 15 秒,如果我删除自定义字体,则需要 1-2 秒使用默认字体显示此活动,但默认的 android urdu 语言字体不是很好。请记住,我从未在 .xml 文件中使用过任何字体活动。任何想法 ?

我的Java代码:

public class JismPics extends Activity {
    TextView txtView;
@Override
   protected void onCreate(Bundle savedInstanceState) { 
   super.onCreate(savedInstanceState);
   setContentView(R.layout.jism_pics);

    txtView = (TextView) findViewById(R.id.textResult);
    Typeface myCustomFont = Typeface.createFromAsset(getAssets(), "fonts/noori.ttf");
    txtView.setTypeface(myCustomFont);

  }
}
4

1 回答 1

0

我在我开发的许多应用程序中使用自定义字体并且从未遇到过这个问题。也许您可以覆盖视图,这样您就不必更改onCreate()方法上的字体

像这样的东西:

public class MyTextView extends TextView
{

public MyTextView(Context context, AttributeSet attrs, int defStyle)
    {
        super(context, attrs, defStyle);
        Typeface font = Typeface.createFromAsset(context.getAssets(), "fonts/NeoSans.otf");
        this.setTypeface(font);
    }

public MyTextView(Context context, AttributeSet attrs)
    {
        super(context, attrs);
        Typeface font = Typeface.createFromAsset(context.getAssets(), "fonts/NeoSans.otf");
        this.setTypeface(font);
    }
public MyTextView(Context context)
    {
        super(context);
        Typeface font = Typeface.createFromAsset(context.getAssets(), "fonts/NeoSans.otf");
        this.setTypeface(font);
    }

}

不要忘记在布局上调用您的自定义类。

<com.myproject.util.guicomponents.MyTextView
                  android:id="@+id/txt_name"
                  android:textSize="22sp"
                  android:layout_width="wrap_content"
                  android:layout_height="match_parent"
                  android:text="@string/txt_reg_name"                             
                  android:layout_gravity="center_vertical"
                  android:layout_marginLeft="15dp"
                  />
于 2014-03-17T17:15:00.737 回答