按钮长按/标准触控差异

时间:2018-01-19 07:44:11

标签: android button android-edittext touch long-press

我有两个控件,一个EditText和一个包含按钮的布局。布局就像一个建议框,只要编辑文本获得焦点就会切换其可见性。

当我关注编辑文本时,该框变为可见。现在当我点击其中一个按钮时,edittext失去焦点,因此在我的建议框中将可见性切换为“Gone”。 当我对任何按钮进行长按时,焦点不会在编辑文本上丢失。

如何通过标准触摸实现按钮上的长按行为?这意味着如何通过单击按钮使edittext不会失去焦点。

1 个答案:

答案 0 :(得分:0)

  

意思是如何通过单击使edittext不会失去焦点   按钮。

你必须实现OnFocusChangeListener来实现这一点,看看。

ediitext.setOnFocusChangeListener(new View.OnFocusChangeListener()
    {
        @Override
        public void onFocusChange(View v, boolean hasFocus)
        {
            ediitext.requestFocus();
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);
        }
    });