2016-04-15 85 views
0

我已经尝试了很多方法,但没有一个能够工作,或者可能用于API < 17.任何人都可以告诉我如何在焦点或隐藏键盘时隐藏键盘点击EditText?Android - 在焦点(API> = 17)时隐藏EditText的键盘输入

ViewGroup group = (ViewGroup)findViewById(R.id.f1entrygroup); 
     for (int i = 0, count = group.getChildCount(); i < count; ++i) { 
      View view = group.getChildAt(i); 
      if (view instanceof EditText) { 
       view.setOnFocusChangeListener(focusListener); 
       view.setOnClickListener(entryClickListener); 

       ***//HOW TO DISABLE THE KEYBOARD POP UP AT HERE?*** 

      } 
     } 

感谢

+0

添加代码,你如何尝试。 –

+0

你用哪种方法隐藏键盘 –

+0

@Louise,你需要一个没有键盘的EditText吗? –

回答

1

中的onCreate设置布局后,试试下面的代码()方法隐藏软键盘

EditText edtView=(EditText)findViewById(R.id.editText); 
edtView.setInputType(0); 

当你触摸或者重点SoftInputKeyboard不会弹出。希望它有帮助

+0

' ViewGroup group =(ViewGroup)findViewById(R.id.f1entrygroup);对于(int i = 0,count = group.getChildCount(); i 1){(EditText)视图).setInputType(0); } } } ' –

0

您可以通过调用此方法

public void hideSoftKeyboard(Activity activity) { 
     InputMethodManager inputMethodManager = (InputMethodManager) activity 
       .getSystemService(Activity.INPUT_METHOD_SERVICE); 
     inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0); 
    } 
0
View.OnFocusChangeListener focusListener = (v, hasFocus) -> { 
     if (hasFocus) { 
      InputMethodManager inputMethodManager = (InputMethodManager) context 
        .getSystemService(Activity.INPUT_METHOD_SERVICE); 
      inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), 0); 
     } 
}; 
相关问题