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

ajax防止重複提交

ajax防止重複提交

會發生重提交的原因,大致上是因為考驗人與系統間的耐性~ AJAX(非同步的JavaScript與XM...

小小消防員初體驗

小小消防員初體驗

年月日,5U幼兒園參加消防夏令營。

PDO連接Mysql方式

PDO連接Mysql方式

pexelsphoto 最近因為源碼檢測的原因,才驚覺自己以前的系統撰寫的方式早已不再安全。 所以決...

Recommended reading

Other stories happened at this address

今晚,瓜仔肉拌飯

今晚,瓜仔肉拌飯

醬瓜切碎,蒜頭切片。 將處理好的醬瓜跟蒜頭跟絞肉一起拌勻。 順便也倒了些醬瓜的湯汁、一點米酒、一點醬...

街角豆漿店的日常

街角豆漿店的日常

每天,我總會先出門到街角豆漿店吃個早餐,趁著Mandy跟U還在夢鄉~ 一個人,喝著咖啡吃著早餐,浪費...

沒想過,無心插柳的地瓜葉也能像黃金葛一樣給人滿滿的成就感~

沒想過,無心插柳的地瓜葉也能...

沒想過,無心插柳的地瓜葉也能像黃金葛一樣給人滿滿的成就感~

所以你現在是有多老?

所以你現在是有多老?

這天,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