Android, view background selector, what is the proper way to do my task? -


Text after "

I editText, which can be in 3 states:

1) Enabled, correct input

2) Enabled, incorrect input

3) Disabled

I have 3 background drawables, each matches each state. How to show lucrative illustration for each state? I want to complete this task with the selector. Something like:

  & lt; Selector xmlns: Android = "http://schemas.android.com/apk/res/android" & gt; & Lt; Item Android: state_enabled = "false" android: color = "@color / disable" /> & Lt; Item Android: state_enabled = "true" android: color = "@ color / enbaled_correct_input" /> & Lt; / Selector & gt;  

But how do I identify the selector item, which corresponds to "enabled, incorrect input"? I need another state I can increase the editing text, create a custom state and use it in the selector, but it seems to be working for my work (I only use this selector once in the application I am).

Alternatively, I can call setbackbars in the code and pass the appropriate background to the appropriate states, but this means to dismiss the selector. I want to complete this task with the selector and to expand the editing text and the new visual position. Yes, I'm lazy :) how to do this?

itemprop = "text">

Try this custom drawable (res / drawable /et.xml):

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Selector xmlns: Android = "http://schemas.android.com/apk/res/android" & gt; & Lt; Item Android: state_enabled = "false" android: drawable = "@ drawable / disabled" /> & Lt; Item Android: state_enabled = "true" & gt; & Lt; Level List & gt; & Lt; Android Android: minLevel = "0" Android: maxLevel = "0" Android: Droplet = "@Drawable / Invalid" /> & Lt; Android Android: minLevel = "1" Android: maxLevel = "1" Android: drawable = "@ drawable / valid" /> & Lt; / Level-list & gt; & Lt; / Item & gt; & Lt; / Selector & gt;  

Trial code:

  Take the linear layout = new linerlight (this); Ll.setOrientation (LinearLayout.VERTICAL); Last edit text and = new edit text (this); Et.setBackgroundResource (R.drawable.et); Et.setEnabled (false); Button b = new button (this); B.setText ("Enable / Disable"); Ll.addView (at); Ll.addView (b); SetContentView (LL); B.setOnClickListener (New OnClickListener) {@Override Public Zero onClick (see v) {et.setEnabled (et.isEnabled ());}}}); et.addTextChangedListener (New TextWatcher () {@Override public void onTextChanged (CharSequence s, int start, before int, int count) {} @Override public void beforeTextChanged (CharSequence s, int start, since the integer count, int) { } @public zeros afterTextChanged (editable) override {et.getBackground () setLevel. (S.length () == 0 0: 1);}});  

Comments