Loading...

Android Studio 2.3 隨機改變背景顏色

Temperature: 0 °C

ChungChung
author_tools


Android Studio 2.3 隨機改變背景顏色
開始學習APP

其實照著工具書上的方式總是在宣告變數時會產生問題~

例如工具書上寫著可以直接拉一個LinearLayout然後給個ID,之後背景色就可以顯示在這邊。

測試結果失敗⊙_⊙

最後還是決定在LinearLayout裡再給一個TextView再下ID~

測試結果成功。

MainActivity.java部分

protected void changeColor(View v){
//取得3個顏色物件及背景色ID
TextView txvR = (TextView) findViewById(R.id.txvR);
TextView txvG = (TextView) findViewById(R.id.txvG);
TextView txvB = (TextView) findViewById(R.id.txvB);
TextView colorBlock = (TextView) findViewById(R.id.colorBlock);
//亂數取出紅色
Random x=new Random();
int red=x.nextInt(256);
txvR.setText("紅:"+ red);
txvR.setTextColor(Color.rgb(255,255,255));
//亂數取出綠色
int green=x.nextInt(256);
txvG.setText("綠:"+ green);
txvG.setTextColor(Color.rgb(255,255,255));
//亂數取出藍色
int blue=x.nextInt(256);
txvB.setText("藍:"+ blue);
txvB.setTextColor(Color.rgb(255,255,255));
//將顏色寫入背景色
colorBlock.setBackgroundColor(Color.rgb(red,green,blue));

}

以上紀錄。

台北市內湖區江南街71巷75弄 Go

https://innstory.com/story-Android_Studio_23_隨機改變背景顏色-1168
寫程式筆記

Prev
 抓周

Next
看不透的事情太多 

Nearby Attractions

台北市內湖區江南街71巷75弄-Nearby Attractions

  • 閻錫山故居 Go
  • 臺北撫臺街洋樓 Go
  • 婦聯總會 Go
  • 自由之家 Go
  • 臺灣民主紀念園區 Go
  • 張?故居 Go

About the Author

Chung

我是chung
網路工作者
主業是網站系統開發建置
副業是做夢,寫故事
作品請參考/teme.biz
做夢請參考/innstory.com
聯絡/chung.teme@gmail.com

#有人用筆寫日記,有人用歲月寫日記,有人用照片寫日記,而我,用innstory寫日記。

Visitor message

Leave some footprints to prove that you visited me

Recommended reading

Author's other related stories

黑客松Hackathon(二)

黑客松Hackathon(二...

這是一次不同的體驗... 我一直都渴望有所謂的工作團隊並且享受共同討論共同創作的樂趣... 這次在黑...

圖文穿插效果

圖文穿插效果

寫故事還是得圖文穿插看起來方便些~ 其實一直都在找最適合寫故事的方式,一開始我把所有上傳照片都放在故...

圖型插件Elastislide

圖型插件Elastislid...

teach Elastislide是一款好用的圖形插件......

Recommended reading

Other stories happened at this address

知道自己不夠高,還特地去客廳搬他的寶物箱進來墊著,我是該哭還是該笑呢?

接下來,一團亂....

知道自己不夠高,還特地去客廳...

知道自己不夠高,還特地去客廳搬他的寶物箱進來墊著,我是該哭還是該笑呢? 接下來,一團亂....

日是好日,年是好年,2017年新年快樂!!

日是好日,年是好年,2017...

即將到來的年會是個什麼樣的年呢? 年的日子,家裡有了新成員~ 而我,當了爸爸。 對我的人生來說~是個...

一兩黑殼蝦的功力

一兩黑殼蝦的功力

養魚養了快年~從台東養到台北。 當然,我一直都不是專業的養魚養草達人,對於水族裡的生態也一直都採放任...

一家人平平安安最幸福

一家人平平安安最幸福

一家人平平安安最幸福

發發來囉~還表演了很多才能哩!!非常厲害爬啊~

發發來囉~還表演了很多才能哩...

發發來囉~還表演了很多才能哩!!非常厲害爬啊~

噓~

噓~

年紀越來越大,古靈精怪的表情越來越多~ 現在還會噓我咧~ 只是,你是否手指比錯方向啊?

Please select an option

error

Hi, thank you for your participation, but you cannot vote repeatedly~

Join innstory now and start recording your story.

"Innstory" is a place to store stories. We are committed to becoming a warm platform. Deepening the bonds between people is our direction.
We are convinced that the blockchain between people is not just a cold calculation. Join us now.

Wrong format