How do I change a button's background color then revert back

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

How do I change a button's background color then revert back

Postby ameetnsharma » Tue Jan 05, 2010 7:45 pm

I wish to be able to set a button's background color... but then later I want to switch it back to the default looking button. How do I do this? Once I set the color, I can't find a way to switch it back.... there's setBackgroundResource, but what's the resouriceid?

Thanks.
ameetnsharma
Developer
Developer
 
Posts: 30
Joined: Tue Dec 08, 2009 10:55 pm

Top

Postby jwei512 » Fri Jan 08, 2010 2:20 am

Hey,

Not sure if you ever figured out your question, but here's the code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.  
  4. // set the button's background color to RED
  5.  
  6. button.setBackgroundColor(Color.RED);
  7.  
  8.  
  9.  
  10. // set the button's background to Android default
  11.  
  12. button.setBackgroundResource(android.R.drawable.btn_default);
  13.  
  14.  
  15.  
  16.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
- jwei

http://thinkandroid.wordpress.com
Examples, Code, and Tutorials
jwei512
Senior Developer
Senior Developer
 
Posts: 135
Joined: Mon Jul 27, 2009 9:35 pm
Location: Palo Alto, CA

Postby ameetnsharma » Fri Jan 08, 2010 3:20 am

jwei512 wrote:Hey,

Not sure if you ever figured out your question, but here's the code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. // set the button's background color to RED
  3. button.setBackgroundColor(Color.RED);
  4.  
  5. // set the button's background to Android default
  6. button.setBackgroundResource(android.R.drawable.btn_default);
  7.  
  8.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


Thanks so much! No, I didn't figure it out. I'd given up on it till now! Thanks again!
ameetnsharma
Developer
Developer
 
Posts: 30
Joined: Tue Dec 08, 2009 10:55 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 5 guests