android學習之 隨機色的定義與獲取

2021-09-21 22:18:42 字數 1120 閱讀 6784

在學取色的時候**寫的想當然了,結果弄了半天顏色一直不變,仔細看後才發現問題,見**

package

sucre.android; 

import

import

android.os.bundle; 

import

android.view.view; 

import

android.widget.button; 

import

android.widget.textview; 

/*** 通過定義乙個color.xml,然後讓字型隨機變色,這裡在取色的時候

* 要注意乙個問題,getresources().getcolor(你定義的顏色)這樣才

* 能真正取到相應的顏色

* @author qiaolei**/

public

class

ex03_13 

extends

activity ; 

column = 0

; bt = (button)findviewbyid(r.id.mbutton); 

tv = (textview)findviewbyid(r.id.changcolor); 

bt.setonclicklistener(new

button.onclicklistener()else } 

}); 

} } 

注意到文中的

tv.settextcolor(colors[column]); 

這行**了嗎?這樣是取不到顏色的,為了驗證通過

system.out.println(colors[column]+

":"+getresources().getcolor(colors[column]));  

這行**得到結果

看到了-65536才是真正的顏色的值,直接這樣寫

tv.settextcolor(-

65536

);  也是可以變色的,所以取色的時候要這樣取

getresources().getcolor(colors[column])

Android之旅 夢想 學習 堅持 自信 淡定

前段時間參加了2012年度it部落格大賽,進了前十強,寫了一篇獲獎感言,不過還沒正式在csdn發表出來。眼看2012年就要結束了,剛好借這個機會將2012年度it部落格大十強獲獎感言發表出來,也算是對2012年部落格的乙個總結,關鍵字是 夢想 學習 堅持 自信 淡定 希望大家一如既往地支援老羅的cs...

Android學習之 TextView的滑動效果

在xml中定義 在activity中為這個textview設定 textview textview this.findviewbyid r.id.textview textview.setmovementmethod scrollingmovementmethod.getinstance 自定義這個...

(1)Android學習之Android 專案結構

宣告應用程式包 android allowbackup true android icon mipmap ic launcher 應用程式圖示 android label 應用程式標籤,即應用程式指定名稱 android roundicon mipmap ic launcher round andr...