天天看點

Android代碼中動态改變字型顔色

titleView.setTextColor(Color.BLUE);

很多時候都需要用在Java代碼中去更改字型的顔色,密碼的顯示方式,以及使用java代碼建立一個控件、一個布局,這次遇到的問題就是使用java代碼更改字型的顔色,第一次使用的是

[java] view plain copy

//  tvAbcAccount.setTextColor(color.PressAccountTextColor);  
//  tvVBcdAccount.setTextColor(color.AccountTextColor);  
      

PressAccountTextColor和AccountTextColor是在colorlist.xml中定義的兩種顔色值

[java] view plain copy

#b5b5b5  
#e7e7e7  


   目的是當有按鍵被按下的時候就對字型顔色進行相應的改變,但是上述代碼不能達到想要的結果,後來查找了一下資料,改為
      
tvAbcAccount.setTextColor(getResources().getColor(R.color.PressAccountTextColor));  
tvBcdAccount.setTextColor(getResources().getColor(R.color.AccountTextColor));  
      
下一篇: git push問題