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
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.
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);
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
StateListDrawable stateList = new StateListDrawable();
stateList.addState(new int[] {
android.R.attr.state_pressed
}, context.getResources().getDrawable(android.R.drawable.list_selector_background));
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