ssummeraw 2013-08-28 08:46 采纳率: 10%
浏览 3030
已采纳

Android textView 中 onCreate 方法的改变

我在main.xml上使用 Layout Editor创建了一个textview名称是textView1。
我想使用一个自定义的字体,所以我在onCreate方法中创建了下面的代码,但是好像不能识别textView1。

package com.mystraldesign.memorable;

import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;

public class MemorableActivity extends Activity 
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Typeface type = Typeface.createFromAsset(getAssets(),"fonts/optima.ttf"); 
        textView1.setTypeface(type);
    }
}

什么原因呢?

  • 写回答

2条回答 默认 最新

  • JaveZh 2013-08-28 08:54
    关注
        TextView textView1=(TextView)findViewById(R.id.textView1);//mail.xml里这个textview的id
        Typeface type = Typeface.createFromAsset(getAssets(),"fonts/optima.ttf"); 
        textView1.setTypeface(type);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • Curie-87 2013-08-29 02:07
    关注

    请初始化 TextView

    public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          // Font path
          String fontPath = "fonts/optima.ttf";
          // text view label
          TextView textView1= (TextView) findViewById(R.id.name);
         // Loading Font Face
          Typeface tf = Typeface.createFromAsset(getAssets(), fontPath);
         // Applying font
          textView1.setTypeface(tf);
      }
    
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#c++#的问题:在A和B类中应该怎么定义复制构造函数来避开unordered_set复制构造的问题(相关搜索:头文件)
  • ¥15 MICE包多重插补后数据集汇总导出
  • ¥15 一道算法分析问题(关于3-MSAT)
  • ¥15 C++ FLUENT 化学反应速率 编写困难
  • ¥15 Python嵌套交叉验证
  • ¥15 linuxkit+elasticsearch
  • ¥15 兄得萌6.13do题😭😭大一小东西的work
  • ¥15 投不到原始数据,gdal投影代码
  • ¥20 卷积混响的代码帮写。。
  • ¥88 借助代码处理雷达影像,识别任意区域洪水前后的被淹没区域,并可视化展示。