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

php函式紀錄

php函式紀錄

常常忘記,只得紀錄下來...... AddSlashes: 字符串加入斜線。 binhex: 二進位...

PHP的日期加減運算

PHP的日期加減運算

在再加上5天 = $years = date("Y"); //用date()函式...

臺北典藏植物園

臺北典藏植物園

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

Recommended reading

Other stories happened at this address

Taare Zameen Par 心中的小星星

Taare Zameen P...

晚餐時間,看了一部印度電影【Taare Zameen Par】 taarezameenpar 一部很...

系統換裝

系統換裝

新的首頁配色排版,目前還看的順眼。 當然還是有許多地方需要調整... 只能說,這真的是一條不歸路啊....

HTML5 Geolocation

HTML5 Geolocat...

說真的,HTML Geolocation的功能真的好用... 輕鬆就可以讓網站也能取得目前所在的地理...

這是~菠蘿麵包.....

這是~菠蘿麵包.....

我記得我買的是菠蘿麵包..... 怎麼被U吃過後,突然覺得這麵包很可憐啊~~~ 這傢伙只給我拔下那金...

清炒長年菜佐5U的咿咿呀呀

清炒長年菜佐5U的咿咿呀呀

在台灣,我們客家人一直對長年菜有種特殊的情感。 逢年過節的時候家裡常會煮上鹹菜湯、梅干扣肉...等年...

看來我們家有好些日子可以充滿南洋風味~

看來我們家有好些日子可以充滿...

看來我們家有好些日子可以充滿南洋風味~

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