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

地圖故事

地圖故事

map 一切都從第一張畫布開始... Innstory裡原先已有寫故事的功能,接著我把故事裡頭的照片...

CSS透明度

CSS透明度

CSS 透明度的實作, 各種瀏覽器和標準如下:(數字越小越透明) 標準: opacity:~ (Fi...

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

Html編輯器Ckedito...

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

Recommended reading

Other stories happened at this address

下一站,父親。

下一站,父親。

i 我無法掩飾我內心的喜悅... 為了等待你的到來,我跟你媽媽也歷經了數個年頭的等待、期待... 因...

當兒子非常非常需要你的時候~

當兒子非常非常需要你的時候~...

當兒子非常非常需要你的時候~ 不得不我只好改變我的工作環境.........(╯з╰) s 硬生生的...

9個月了​​​​​​​,有時希望他快點長大​​​​​​​,有時又希望時間慢一點​​​​​​​。

9個月了​​​​​​​,有時...

s 個月了,看看這傢伙學會了些甚麼? 笑點一樣很低,呵呵呵的笑聲總是能讓我暫時放下手邊的一切只是看著...

5U脫逃記,哥要的是自由啊~

5U脫逃記,哥要的是自由啊~...

Mandy為了小傢伙添購了一個籠(安全柵欄)。 s 也在我充滿設計感的眼光下拼裝完成~ 為的是希望U...

天!39快要失守了~

天!39快要失守了~

今早,FB傳來一個訊息...因為一位同學生日到了..... 我看著FB畫面中顯示著同學歲.... 靠...

為了維護世界和平!!

為了維護世界和平!!

既然你誠心誠意的問了,那我就大發慈悲的告訴你~ 為了拯救動物星球的青蛙先生跟長頸鹿小姐~ 為了跟邪惡...

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