如何在TextView中使用真实字体?

时间:2013-08-12 11:58:04

标签: java android

我试图实现" Font Awesome"侮辱这个 source

我做了这些程序但是我的申请一旦关闭就关闭了。
这有什么问题?

  1. 我复制了values/attrs.xml。并粘贴到我的申请表(内容没有变化)

  2. 我复制了values/strings.xml的内容,并粘贴到我的应用中的strings.xml中。

  3. 我复制了layouts/icon.xmlgrid.xml,并粘贴到我的应用中(内容无变化)

  4. 我复制了assets/icons.ttf,并粘贴到了我的应用中(内容没有变化。它是一个字体文件)

  5. 我将src/com.example.IconView/IconView.java复制到我的应用中(内容没有变化)

  6. 我将这些行添加到MainActivity.java

    setContentView(R.layout.grid);
    GridView grid = (GridView) findViewById(R.id.gridview);
    grid.setAdapter(ArrayAdapter.createFromResource(this, R.array.icons, R.layout.icon));   
    
  7. 然后我的当前代码看起来像这样

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        setContentView(R.layout.grid);
        GridView grid = (GridView) findViewById(R.id.gridview);
        grid.setAdapter(ArrayAdapter.createFromResource(this, R.array.icons, R.layout.icon));       
    
        mActionBar = getActionBar();
        mActionBar.hide();
    

    然而,我的应用程序一推出就会自动关闭。
    我该如何解决这些问题,并使字体真棒?

    logcat的

    08-12 21:07:35.931: E/Trace(31646): error opening trace file: No such file or directory (2)
    08-12 21:07:36.041: D/webcoreglue(31646): netstack: Memory Cache feature is ON
    08-12 21:07:36.062: W/(31646): init htc webcore
    08-12 21:07:36.122: W/dalvikvm(31646): threadid=1: thread exiting with uncaught exception (group=0x40e19468)
    08-12 21:07:36.122: E/AndroidRuntime(31646): FATAL EXCEPTION: main
    08-12 21:07:36.122: E/AndroidRuntime(31646): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sample/com.example.sample.MainActivity}: java.lang.NullPointerException
    08-12 21:07:36.122: E/AndroidRuntime(31646):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2355)
    08-12 21:07:36.122: E/AndroidRuntime(31646):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391)
    08-12 21:07:36.122: E/AndroidRuntime(31646):    at android.app.ActivityThread.access$600(ActivityThread.java:151)
    08-12 21:07:36.122: E/AndroidRuntime(31646):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1335)
    08-12 21:07:36.122: E/AndroidRuntime(31646):    at android.os.Handler.dispatchMessage(Handler.java:99)
    08-12 21:07:36.122: E/AndroidRuntime(31646):    at android.os.Looper.loop(Looper.java:155)
    08-12 21:07:36.122: E/AndroidRuntime(31646):    at android.app.ActivityThread.main(ActivityThread.java:5511)
    08-12 21:07:36.122: E/AndroidRuntime(31646):    at java.lang.reflect.Method.invokeNative(Native Method)
    08-12 21:07:36.122: E/AndroidRuntime(31646):    at java.lang.reflect.Method.invoke(Method.java:511)
    08-12 21:07:36.122: E/AndroidRuntime(31646):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
    08-12 21:07:36.122: E/AndroidRuntime(31646):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796)
    08-12 21:07:36.122: E/AndroidRuntime(31646):    at dalvik.system.NativeStart.main(Native Method)
    08-12 21:07:36.122: E/AndroidRuntime(31646): Caused by: java.lang.NullPointerException
    08-12 21:07:36.122: E/AndroidRuntime(31646):    at com.example.sample.MainActivity.onCreate(MainActivity.java:62)
    08-12 21:07:36.122: E/AndroidRuntime(31646):    at android.app.Activity.performCreate(Activity.java:5066)
    08-12 21:07:36.122: E/AndroidRuntime(31646):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1101)
    08-12 21:07:36.122: E/AndroidRuntime(31646):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2311)
    08-12 21:07:36.122: E/AndroidRuntime(31646):    ... 11 more
    

0 个答案:

没有答案