Here is the EditText
's abc_edit_text_material
drawable XML:
<selector>
<item android:state_enabled="false" android:drawable="@drawable/abc_textfield_default_mtrl_alpha"/>
<item android:state_pressed="false" android:state_focused="false" android:drawable="@drawable/abc_textfield_default_mtrl_alpha"/>
<item android:drawable="@drawable/abc_textfield_activated_mtrl_alpha"/>
</selector>
It defines a set of images but not colours (and I can not track the moment when the colour is applied).
The following piece of code makes the bottom line always stay red, though its thickness changes with focus (so, the same <selector>
is still in use):
Drawable back = edittext.getBackground();
back.setColorFilter(0xffff0000, PorterDuff.Mode.SRC_ATOP);
editText.setBackground(back);
But if after that I restore the default drawable, colours start changing according to the current focus state (gray unfocused, accent focused):
back.setBackgroundResource(R.drawable.abc_edit_text_material);
The questions:
- Why is the same
selector
used after applying a modifiedDrawable
? - Why do colours start to respond to focus changes after re-setting the same XML drawable as the background? Is there some object storing a set of colours corresponding to
selector
'sstate_enabled
, etc? - (Maybe, the answer to this one will also make clear the previous two)
At which moment and how is colour applied by default? I mean, does it check whether the background is default and which class calls for this colouring? I tried looking through the sources fromAppCompatEditText
toView
and did not find anything like that