无法在oncreate中更改TextView样式

时间:2013-06-21 11:23:52

标签: android fonts runnable oncreate

我无法通过我班级的initFonts()函数中的函数onCreate()更改文本样式。没有错误,但没有任何反应。我正在运行一个无限循环的runnable(延迟1秒)。这是一个问题吗?

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);     
        setContentView(R.layout.activity_main); 

        initFonts();

        // Start a load dialog
        progressdialog = new ProgressDialog(MainActivity.this);
        progressdialog.setTitle("Please wait");
        progressdialog.setMessage("Loading...");
        progressdialog.setCancelable(false);
        progressdialog.show();


        // Start updating all lists
        runnable = new Runnable() {
            public void run() {
                updateList();
            }
        }; 

        // Keep it running
        runnable.run();         
    }

我正在更改initFonts()方法中的字体:

TextView cur = (TextView)findViewById(R.id.current);
TextView plus = (TextView)findViewById(R.id.plus);
TextView min = (TextView)findViewById(R.id.min);

cur.setTextSize(150);
Typeface font = Typeface.createFromAsset(getAssets(), "font.ttf");  
cur.setTypeface(font);

plus.getBackground().setAlpha(45);
min.getBackground().setAlpha(45);

1 个答案:

答案 0 :(得分:0)

Typeface font = Typeface.createFromAsset(getAssets(), "foldername/font.ttf");  
cur.setTypeface(font);