在我的工具栏中有一个textView,默认情况下是不可见的。用户在我的edittext中输入内容后,textView应该对用户可见。如何实现这个?
答案 0 :(得分:1)
对于editText视图,您可以添加TextWatcher。
TextWatcher是这样的:
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
int vibility = (TextUtils.isEmpty(charSequence)) ? View.GONE : View.VISIBLE;
textView.setVisibility(vibility);
}
@Override
public void afterTextChanged(Editable editable) {
}
});
答案 1 :(得分:0)
你可以尝试这个:
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()>0){
toolBarTextView.setVisiblity(View.GONE);
toolBarTextView.setText("");
}else {
toolBarTextView.setVisiblity(View.VISIBLE);
toolBarTextView.setText(s.toString());
}
}
});