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

javascript 底下使用 htmlspecialchars

javascript 底下使...

pexelsphoto Javascript中使用一個函數達到PHP的htmlspecialchar...

.sql檔過大無法匯入phpMyAdmin

.sql檔過大無法匯入php...

修改phpMyAdmin資料夾中的config.inc.php檔。 打開後找到下列兩行或自行加入: ...

使用jquery animate達到動態效果

使用jquery anima...

首先..雖然在寫系統時常常會用到jquery 但我並沒有針對他的指令有做太深入的研究... 剛好這一...

Recommended reading

Other stories happened at this address

吃優格可以吃成這樣~⊙_⊙再多塗一點可以敷臉了......

吃優格可以吃成這樣~⊙_⊙再...

吃優格可以吃成這樣~⊙⊙再多塗一點可以敷臉了......

5G滿三個月

5G滿三個月

G滿三個月了。 最近有一點咳嗽,看來還是加入了我們是一家人的行列(╯з╰) 奶量非常難抓,有時cc ...

清除網頁暫存(no cache)

清除網頁暫存(no cach...

pexelsphoto 在製作專案時,有沒有試過JS 或 CSS 明明就已經更新了~ 但頁面卻像鬼打...

1歲9個月

1歲9個月

歲個月~ 凡事都有第一次,對於這麼小的年紀,一切更是新鮮有趣~但可不包括現在這樣子。 人生第一次長針...

發現網路食客

發現網路食客

map 當電腦跟著你的日子越久~ 有時候會突然有些塵封已久的資料突然竄出( ̄∇ ̄) 發現~那年為了網...

假日就是該吃咖哩麵

假日就是該吃咖哩麵

s 假日,可以說是我最放鬆的時間。 不用一個人照顧小孩、不用下廚房煮飯,就算要開伙,廚房的事也是交給...

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