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

Mysql最怕就是手賤

Mysql最怕就是手賤

今天我手賤了眼盲了@@... 錯把delete當成UPDATE....啃!!今天下午超不順的... ...

找對方法,開創自己的網路流量

找對方法,開創自己的網路流量...

前些天,Tim傳來了一個消息...http://classt...

讓圖片上傳前先產生預覽

讓圖片上傳前先產生預覽

專案需要,上傳圖片至網站時先產生預覽圖~ 參考了stackoverflow.com裡討論的的方式

Recommended reading

Other stories happened at this address

外頭下了一整天的雨,系統裡的天氣卻顯示我所在的位置陽光普照?何解?

外頭下了一整天的雨,系統裡的...

外頭下了一整天的雨,系統裡的天氣卻顯示我所在的位置陽光普照?何解?

我以前不可能做這些事~

我以前不可能做這些事~

我以前~ 不可能在坐在電腦前時還得抱著你。 不可能在應該拿著滑鼠的手卻得要拿著奶瓶。 不可能走在外頭...

Linux底下Apache啟動、停止、重啟指令

Linux底下Apache啟...

a 如果apache安裝成為linux的服務的話,可以用以下命令操作: service httpd ...

一本本裝滿記憶的小本子

一本本裝滿記憶的小本子

今天突然想要整理一下我那塵封已久裝滿記憶的箱子~ 其實是為了培養好休假情緒~因為再過不久就是農曆新年...

第一天上學,意外的順利。

第一天上學,意外的順利。

沒有分離焦慮,沒有十八相送。 U第一天上學竟然意外的順利\(^o^)/ 早上帶他去幼稚園,跟他說爸爸...

鍾5U VS 孔雀餅乾

鍾5U VS 孔雀餅乾

午后,點心時間。 U自己拿了孔雀餅乾盒給我,用手指了指然後發出啊啊啊啊的聲音。 我知道他是告訴我他想...

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