[英]After click on editText is done when going to another edittext
I'm having a question where I couldn't find the answer online or know how to find it.. 我有一个问题,我在哪里找不到在线答案或不知道如何找到答案。
I have EditText xml
attribute and I made an event listener to this attribute by changing the color of an underline beneath it. 我具有
EditText xml
属性,并且通过更改其下划线的颜色对该属性进行了事件监听。 Is there a way when the focus is removed from this EditText
(ie user click on any other element rather than this one) to remove the highlighted color for the line I colored? 有没有一种方法可以将焦点从此
EditText
上移开(即用户单击任何其他元素而不是此元素)以除去我上色的行的突出显示的颜色?
On the onclick
event listener? 在
onclick
事件监听器上? It seems weird, but I want the opposite of the onclick
like onclickremove
or something. 看起来很奇怪,但是我想要
onclick
的反义词,例如onclickremove
东西。
You can use the the setOnFocusChangeListener
to your EditText. 您可以将
setOnFocusChangeListener
EditText。 If lost focus,clear the color filter: 如果失去焦点,请清除滤色片:
editText.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
editText.getBackground().setColorFilter(color, PorterDuff.Mode.SRC_IN);
}
else{
editText.getBackground().clearColorFilter();
}
}
});
If you want to change your view color, just add the below line in onFocusChange
: 如果要更改视图颜色,只需在
onFocusChange
添加以下行:
view.setBackgroundColor(Color.parseColor("#ffffff"));
Hope this helps. 希望这可以帮助。
You need to use setOnFocusChangedListener
for this. 您需要为此使用
setOnFocusChangedListener
。 The hasFocus
determines whether the focus is removed or given to a view. hasFocus
确定焦点是被移除还是被赋予视图。 It being false
indicates that user has left the field. 为
false
表示用户已离开该字段。
EditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus == false){
// change the color
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.