gpt4 book ai didi

java - 当焦点状态改变时如何改变 "drawableLeft"?

转载 作者:行者123 更新时间:2023-12-01 04:37:23 25 4
gpt4 key购买 nike

enter image description here

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

有没有简单的方法可以解决这个问题?谢谢先进!

最佳答案

@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);
}
}

关于java - 当焦点状态改变时如何改变 "drawableLeft"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17159628/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com