您好我正在尝试构建应用程序,其中某些字体是从网址加载的,然后应用于 TextView
但它不会工作。
这里是我的简单代码
在oncreate()
中try {
if (new File("/sdcard/a/" + MainActivity.pos + ".ttf").exists()){
mTypeface = Typeface.createFromFile("/sdcard/a/" + MainActivity.pos
+ ".ttf");
tv.setTypeface(mTypeface);
} else {
new DisplayImageFromURL().execute(MainActivity.URL);
}
} catch (Exception e) {
}
在TextView上下载并显示字体样式
private class DisplayImageFromURL extends AsyncTask<String, Void, Typeface> {
ProgressDialog pd=null;
@Override
protected void onPreExecute() {
super.onPreExecute();
pd = new ProgressDialog(Working_Class.this);
pd.setMessage("Downoading file...");
pd.show();
}
protected Typeface doInBackground(String... urls) {
String urldisplay = urls[0];
Typeface mIcon11 = null;
try {
mIcon11=Typeface.createFromFile(urldisplay);//this line not working properly....
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
protected void onPostExecute(Typeface result) {
mTextView.setTypeface(result);
pd.dismiss();
}
}
我希望这样