1.我不想为每个组件写太多选择器。
2.我试着写一个EditText的子类,命名为EditTextDrawable。然后我确实喜欢这个:
public EditTextWithDrawable(Context context, final Drawable normal, final Drawable focus){
super(context);
setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
// changeDrawable(hasFocus, normal, focus);
}
});
但是如果我想重置OnFocusChangeListener,我必须再次输入代码。这很无聊。
有一种简单的方法可以解决这个问题吗?先进了!
答案 0 :(得分:0)
@Override
protected void onFocusChanged(boolean focused, int direction,
Rect previouslyFocusedRect) {
// TODO Auto-generated method stub
super.onFocusChanged(focused, direction, previouslyFocusedRect);
if (focused) {
setCompoundDrawablesWithIntrinsicBounds(fous, null, null, null);
}else {
setCompoundDrawablesWithIntrinsicBounds(normal, null, null, null);
}
}