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

解決FB分享帶參數問題

解決FB分享帶參數問題

又到了FB分享連結的時間了,沒辦法FB太紅...@@... 一般來說如果是以FB的分享網址做分享的方...

修練中

修練中

假日二胡修練中。

在手機上如何建立網址到手機桌面中並且使用圖示

在手機上如何建立網址到手機桌...

上回做專案時,客戶說了手機桌面上的網站捷徑太醜,想要美化。 這回索性也幫Innstory美化一下,順...

Recommended reading

Other stories happened at this address

爸爸,卡住啊~

爸爸,卡住啊~

前陣子U學會個單字。 一個是「怕怕 」,另一個是「 卡住啊」 而且這個單字似乎是他目前最喜歡使用的。...

我們家,在下著豆腐雨呢,看看這傢伙做了些甚麼~

我們家,在下著豆腐雨呢,看看...

我們家,在下著豆腐雨呢,看看這傢伙做了些甚麼~

好久沒去逛魚店了~

好久沒去逛魚店了~

fish 好久,沒有整理我的魚缸了..... 今晚,花了點時間..... 養魚是我興趣來的,但我並不...

獨自一個人的2個星期,第2晚,手機上傳來兒子的新把戲。

獨自一個人的2個星期,第2晚...

一早醒來,發現床原來是這麼的大,而且我還睡在Mandy的位子上。 想想以往我都是睡在床邊上,現在床變...

悠悠變red

悠悠變red

Mandy鬧著U,沒多久這傢伙雙手抱胸然後說「悠悠變red 」,哼!不開心~ 之後沒多久,又說他變y...

5G餵食秀

5G餵食秀

餵食前,一刻也不能等,哭得我心慌意亂。 餵食後,笑中還帶著淚。 我知道妳要的很簡單,但也請妳多給我些...

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