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

小小消防員初體驗

小小消防員初體驗

年月日,5U幼兒園參加消防夏令營。

臺北典藏植物園

臺北典藏植物園

5年寒假前,綠的學校安排了戶外教學,地點臺北典藏植物園。 和同學們一起搭了火車,搭了公車,走路,最後...

地圖故事

地圖故事

map 一切都從第一張畫布開始... Innstory裡原先已有寫故事的功能,接著我把故事裡頭的照片...

Recommended reading

Other stories happened at this address

兒子,吃香蕉要剝皮好嗎⊙_⊙

兒子,吃香蕉要剝皮好嗎⊙_⊙...

兒子,吃香蕉要剝皮好嗎⊙⊙

人生第一次拿到會飛的氣球,這傢伙開心到不行啊~

人生第一次拿到會飛的氣球,這...

人生第一次拿到會飛的氣球,這傢伙開心到不行啊~

下雨天,只能在家被小孩玩~

下雨天,只能在家被小孩玩~

下雨天,只能在家被小孩玩~

1歲7個月

1歲7個月

愛模仿的年紀真的很有趣。 學著我用腳拿、撿起東西、學著Mandy大笑,古靈精怪的傢伙讓我不得不愛上他...

SSL憑證

SSL憑證

pexelsphotossl 終於~為innstory申請了SSL安全憑證。 安裝的過程中出了點狀況...

這是一種你丟我揀的概念....

這是一種你丟我揀的概念......

game 最近兒子經常性的跟我玩一種遊戲.... 就是他吐掉嘴上的奶嘴然後EEAA的叫了幾聲~ 我就...

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