Enable Call Recording on Xperia Z2 and Z3

Call recording, while not legal in every part of the world, is quite handy in certain situations. … more

Google Play Store Payments Available in China

Google has taken a big step to make its services accessible globally. Since the introduction of … more

How to Set a Video as Your Boot Animation

If you wish to make your phone truly unique, you may want to consider adding a nice boot animation. … more

TWRP for Nexus 6 and 9 Available, Unofficial CM12 Alpha for HTC Explorer! – XDA TV

Team Win Recovery Project for the Nexus 6 and Nexus … more

Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

[Q] Set BackgroundColor but keep onTouch

OP Auroratic

20th March 2014, 06:53 PM   |  #1  
Auroratic's Avatar
OP Member
Flag Austria
Thanks Meter: 0
 
45 posts
Join Date:Joined: Jun 2013
More
Hello,
I want to set the BackgroundColor of ListView items, but I want to keep the color which appears when I click the items.

How can I do that?
21st March 2014, 12:34 AM   |  #2  
deanwray's Avatar
Senior Member
Thanks Meter: 429
 
1,145 posts
Join Date:Joined: Apr 2006
Donate to Me
Quote:
Originally Posted by Auroratic

Hello,
I want to set the BackgroundColor of ListView items, but I want to keep the color which appears when I click the items.

How can I do that?

Rather than replace a "stateListDrawable" with a color or static drawable, replace it with another state list that has the "states" you require
21st March 2014, 11:36 PM   |  #3  
Auroratic's Avatar
OP Member
Flag Austria
Thanks Meter: 0
 
45 posts
Join Date:Joined: Jun 2013
More
Quote:
Originally Posted by deanwray

Rather than replace a "stateListDrawable" with a color or static drawable, replace it with another state list that has the "states" you require

I've got it, but I have one problem: The colour on state_pressed should be the default system colour (this one: android.R.drawable.list_selector_background)
How can I do that?
Last edited by Auroratic; 22nd March 2014 at 02:22 AM.
22nd March 2014, 04:11 AM   |  #4  
deanwray's Avatar
Senior Member
Thanks Meter: 429
 
1,145 posts
Join Date:Joined: Apr 2006
Donate to Me
Quote:
Originally Posted by Auroratic

I've got it, but I have one problem: The colour on state_pressed should be the default system colour (this one: android.R.drawable.list_selector_background)
How can I do that?

I'm not sure what your asking, if you have read about stateListDrawabes and have understood it, also maybe even looked at examples, then you should know ? Open that resource, or even clone it and edit it how you want.
22nd March 2014, 12:50 PM   |  #5  
Auroratic's Avatar
OP Member
Flag Austria
Thanks Meter: 0
 
45 posts
Join Date:Joined: Jun 2013
More
Quote:
Originally Posted by deanwray

I'm not sure what your asking, if you have read about stateListDrawabes and have understood it, also maybe even looked at examples, then you should know ? Open that resource, or even clone it and edit it how you want.

I have the following:
Code:
StateListDrawable stateList = new StateListDrawable();
stateList.addState(new int[] {
   android.R.attr.state_pressed
}, new ColorDrawable(android.R.drawable.btn_default));

stateList.addState(new int[0], new ColorDrawable(Color.YELLOW));
textView.setBackgroundDrawable(stateList);
The background is yellow, but when I press on the textView, the background turns into transparent (it should be like this when i press:
)
22nd March 2014, 02:35 PM   |  #6  
deanwray's Avatar
Senior Member
Thanks Meter: 429
 
1,145 posts
Join Date:Joined: Apr 2006
Donate to Me
Quote:
Originally Posted by Auroratic

I have the following:

Code:
StateListDrawable stateList = new StateListDrawable();
stateList.addState(new int[] {
   android.R.attr.state_pressed
}, new ColorDrawable(android.R.drawable.btn_default));

stateList.addState(new int[0], new ColorDrawable(Color.YELLOW));
textView.setBackgroundDrawable(stateList);
The background is yellow, but when I press on the textView, the background turns into transparent (it should be like this when i press:
)

well fyi you should look at the view type "states" as not sure you want android.R.attr.state_pressed ... neways you probably want state_focused and state_enabled for an editText view, but really google should provide you with simple absolute answers

hope that clears it up neways
22nd March 2014, 03:05 PM   |  #7  
Auroratic's Avatar
OP Member
Flag Austria
Thanks Meter: 0
 
45 posts
Join Date:Joined: Jun 2013
More
Quote:
Originally Posted by deanwray

well fyi you should look at the view type "states" as not sure you want android.R.attr.state_pressed ... neways you probably want state_focused and state_enabled for an editText view, but really google should provide you with simple absolute answers

hope that clears it up neways

I have that now:
Code:
StateListDrawable stateList = new StateListDrawable();
        stateList.addState(new int[] {
            android.R.attr.state_pressed
        }, context.getResources().getDrawable(android.R.drawable.list_selector_background));
but when I press on the TextView, the background goes orange
Last edited by Auroratic; 22nd March 2014 at 03:26 PM.
22nd March 2014, 03:31 PM   |  #8  
deanwray's Avatar
Senior Member
Thanks Meter: 429
 
1,145 posts
Join Date:Joined: Apr 2006
Donate to Me
Quote:
Originally Posted by Auroratic

I have that now:

Code:
StateListDrawable stateList = new StateListDrawable();
        stateList.addState(new int[] {
            android.R.attr.state_pressed
        }, context.getResources().getDrawable(android.R.drawable.list_selector_background));
but when I press on the TextView, the background goes orange

now your setting a state with a state "list" so not sure that will ever work.. needs to be a simple drawable

Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes