有什么办法可以从Textview的URL设置setTypeFace? [英] Any way to setTypeFace from url for a Textview?

查看:141
本文介绍了有什么办法可以从Textview的URL设置setTypeFace?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过url设置setTypeFace,例如: https: //github.com/anak10thn/frontend-homepage/raw/master/font/helvetica-regular.otf

I want to setTypeFace from url like : https://github.com/anak10thn/frontend-homepage/raw/master/font/helvetica-regular.otf

您知道是否有办法吗?

Do you know if there any way ?

我尝试了此操作:

                Typeface tf = Typeface.createFromFile("https://github.com/anak10thn/frontend-homepage/raw/master/font/helvetica-regular.otf");

            tv.setTypeface(tf);

它不起作用。

我有这个错误:

03-24 04:46:59.931    1314-1314/bya.fchps.buildyourapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: bya.fchps.buildyourapp, PID: 1314
java.lang.RuntimeException: Unable to start activity ComponentInfo{bya.fchps.buildyourapp/com.fchps.buildyourapp.views.ClassicView}: java.lang.RuntimeException: native typeface cannot be made
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
        at android.app.ActivityThread.access$800(ActivityThread.java:135)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5017)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
        at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.RuntimeException: native typeface cannot be made
        at android.graphics.Typeface.<init>(Typeface.java:175)
        at android.graphics.Typeface.createFromFile(Typeface.java:159)
        at com.fchps.buildyourapp.views.ClassicView.setClassicLabel(ClassicView.java:178)
        at         com.fchps.buildyourapp.views.ClassicView.onCreate(ClassicView.java:75)
        at android.app.Activity.performCreate(Activity.java:5231)
        at   android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
        at            android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)


推荐答案

嗨您不能直接在Typeface中添加字体的URL。如果要在应用程序中动态使用字体,最好的选择是应用程序将在本地设备中下载第一个字体。然后定义字体在字体中的路径。

Hi You can not directly add the URL of font in Typeface. If you want to dynamically use the font in your application, the best option is application would download fist font in local device. Then define the path of font in to the Typeface.

Typeface typeface = Typeface.createFromFile(
    new File(Environment.getExternalStorageDirectory(), "font.ttf"));

这篇关于有什么办法可以从Textview的URL设置setTypeFace?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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