1

在此处输入图像描述

1.我不想给每个组件写太多的选择器。

2.我尝试编写一个名为EditTextDrawable 的EditText 子类。然后我这样做了:

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,我必须再次输入代码。这很无聊。

有没有简单的方法来解决这个问题?tks先进!

4

1 回答 1

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);
    }
}
于 2013-06-18T02:54:59.813 回答