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

Photoshop 曲線文字建置

Photoshop 曲線文字...

Photoshop一直都是很強悍的繪圖軟體。 裡頭的【鋼筆工具】,可以拉貝茲曲線的.... 我剛開始...

DIV區塊內文字左右對齊?

DIV區塊內文字左右對齊?

最近常接到一些英文網站建置的專案....為了讓內容文字能夠左右對齊... 所以我用了以下方式 div...

關於資安防護

關於資安防護

一直以來我都不敢寫跟資安有關的文章..對我來說...資安一直是一個課題..XSS...CSRF......

Recommended reading

Other stories happened at this address

39週,已經突破3300公克了......

39週,已經突破3300公克...

Dear 小小鍾~ 週了,今天醫生阿伯說你已經突破公克了......應該要出來了~ 我幫你看了一下,...

四個月又2天,翻身

四個月又2天,翻身

瞧她一臉有點小驚訝的表情卻又按耐不住喜悅貌。 四個月又天,自己翻身成功,似乎好像不大相信自己成功了。...

剪髮初體驗~

剪髮初體驗~

第天,剪髮初體驗~由阿婆親自操刀。 這傢伙很淡定啊,看來他根本不知道即將要發生什麼事。 果然,阿婆還...

你多久沒有展翅高飛了?

你多久沒有展翅高飛了?

s 多久?沒有展翅高飛了? 隨著年紀越大,卻越不夠勇敢。 愛作夢的年紀,漸漸的被現實中的生活所取代~...

麻油雞泡飯

麻油雞泡飯

再一次,又到了麻油雞酒的季節。 is sesame oil chicken season again...

鄰居種植的鬼椒,據說很辣,歡迎我們採用,但我實在沒有勇氣嚐試@@

鄰居種植的鬼椒,據說很辣,歡...

鄰居種植的鬼椒,據說很辣,歡迎我們採用,但我實在沒有勇氣嚐試@@

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