Edittext 的变化监听、图片设置
edittext的变化监听有addTextChangedListener,code:
editText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { if (s.length() > 5) textView1.setText("大于 5"); else textView1.setText("小于 5"); } });
也可以以接口的形式写入
TextWatcher textWatcher;//定义一个watcher textWatcher = new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { if (s.length() > 5) textView1.setText("大于 5"); else textView1.setText("小于 5"); } }; editText.addTextChangedListener(textWatcher);
动态对edittext的图片进行改变
Drawable drawable = getResources().getDrawable(R.mipmap.ic_launcher); drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); editText.setCompoundDrawables(drawable, drawable, null, null); //四个参数代表四个位置,左上右下