Change BG color onClick

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

Change BG color onClick

Postby xdm87 » Tue Jan 12, 2010 8:38 am

How do I change the background color of a TextView when it's being pressed? I *don't* mean just setBackgroundColor. For example, when you click something in the Messages application, it will turn yellow. If you hold-click it, it will turn yellow, then white, then show a menu. My application already supports both clicks and long clicks, but how do I get the background to behave that way?
xdm87
Freshman
Freshman
 
Posts: 4
Joined: Tue Jan 05, 2010 6:19 am

Top

Postby jwei512 » Wed Jan 13, 2010 3:36 am

Do you actually want to set up a Context menu (the thing you're describing) or do you just want to mimic the color change thing?
- 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 xdm87 » Wed Jan 13, 2010 6:01 am

Changing colors on click and on long click -- is it something built into ListViews?
xdm87
Freshman
Freshman
 
Posts: 4
Joined: Tue Jan 05, 2010 6:19 am

Postby jwei512 » Wed Jan 13, 2010 7:30 am

Ooph not sure... maybe it's possible to register a Context menu but not actually have any menu options? In other words when you override onContextMenuCreate() just return true and don't create any menu items.

That might simulate the color change effect without providing any menus.
- 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 icobasco » Thu Jan 14, 2010 10:42 am

I think you (xdm87) are not talking about a simple TextView...
In the example you shown, the Message is an item inside a ListView, which is its selector (customizable) which can understand if it's has been pressed for a while or just clicked and re-draw the background.

If I'm right, you need to use selectors and not do the changes "by yourself".
User avatar
icobasco
Senior Developer
Senior Developer
 
Posts: 108
Joined: Thu Jun 04, 2009 11:12 am
Location: Italy

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Google [Bot] and 5 guests