当键盘弹出时隐藏ImageView,并在键盘消失时显示它。

8

当键盘弹出后(在某个EditText上按下后),我该如何隐藏ImageView。然后在键盘消失时显示这个ImageView?

2个回答

3

我认为OnFocusChangeListener可能是适合你的东西。

editText.setOnFocusChangeListener(new OnFocusChangeListener() {

    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        // view/hide ImageView
    }
});

4
它运行良好。但我遇到了另一个问题。按下返回按钮隐藏键盘后,EditText不会失去焦点,因此ImageView仍然被隐藏。是否有用于解除键盘的某个监听器? - Procurares
@Procurares 很高兴你喜欢它!如果它对你有帮助,请点赞/接受答案。是的,这是可能的。请阅读该链接以了解如何操作:https://dev59.com/Ym855IYBdhLWcg3wfUZM - poitroae

3
edit_Text.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
    if(hasFocus){
        Toast.makeText(getApplicationContext(), "got the focus", Toast.LENGTH_LONG).show();
             // Hide your ImageView
               iv.setVisibility(View.GONE);  // (make the view gone)
    }else
        Toast.makeText(getApplicationContext(), "lost the focus", Toast.LENGTH_LONG).show();
            // Show your ImageView
              iv.setVisibility(View.VISIBLE);
    }
});

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接