2013-06-21 126 views
0

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

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); 
+0

检查font.ttf文件..是它的任何文件夹中。? – Riser

+0

是的,它在文件夹 – user6827

+0

看到我的答案在下面。 – Riser

回答

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

不行,这是行不通的,它是在资产根文件夹 – user6827

+0

中放上你编辑好的代码。 – Riser

+0

它是textview不起作用。我甚至不能设置一个听众 – user6827