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數字轉國字...

什麼鬼...客戶系統的需求竟然有一個數字要轉成國字.... 數字轉國字...數字轉國字...就是要把...

利用 css 讓 ul 置中呈現

利用 css 讓 ul 置中...

以前寫網站...總是喜歡用Table 包住內容.. 而隨著時空的轉換...現在大都用div..或者....

PHP如何將陣列組合接成字串

PHP如何將陣列組合接成字串...

$arr = array(&#;hello&#;,&#;word&#;); echo implode...

Recommended reading

Other stories happened at this address

發現網路食客

發現網路食客

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

Html編輯器Ckeditor 4.0內容讀取與寫入方式

Html編輯器Ckedito...

ckor 在Html編輯器裡,Ckor功能很強大雖然好用....但還是有很多部份需要微調啊... 原...

看來白川鄉,得再去一次了~

看來白川鄉,得再去一次了~

看來白川鄉,得再去一次了~

就是要一杯美式配上小美手工鳳梨酥...

就是要一杯美式配上小美手工鳳...

繼天然美味好吃的小美冰淇淋....啊不...是手工餅乾後.... 我心中的烘培達人小美,又一力作,小...

爸爸媽媽你看~rainbow

爸爸媽媽你看~rainbow...

看著U排著字母色筆,當然這已經不是他第一次排列。 我跟Mandy只是在旁回應著他的呼喚,爸爸你看、媽...

口腔期加上爬行,有時候不禁懷疑我養的到底是小孩還是蛞蝓?

口腔期加上爬行,有時候不禁懷...

口腔期加上爬行,有時候不禁懷疑我養的到底是小孩還是蛞蝓?

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