如何在Android中的AutoCompleteTextView的Activity启动时显示键盘
我们希望在AutoCompleteTextView的活动启动时显示键盘默认值。 但AutocompletedTextview放置在其中一个片段类中。当fragement开始默认时,我们的键盘已显示。如何在Android中的AutoCompleteTextView的Activity启动时显示键盘
我们试图用三种情况:
案例1:
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
案例2:
auto_phone.requestFocus();//auto_phone is AutoCompleteTextView
auto_phone.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((event.getAction() == KeyEvent.ACTION_DOWN && (keyCode == KeyEvent.KEYCODE_ENTER))) {
return sendChatMessage();//method
}
return false;
}
案例3:
InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(auto_phone, 0);
我们在清单文件中使用也为作为键盘Visibl的活动e
请指导我们。 高级谢谢!
这对我的作品
public static void showSortKeyboard(View focusedView, Activity activity) {
if (focusedView == null) {
return;
}
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(focusedView, InputMethodManager.SHOW_IMPLICIT);
}
感谢效应初探。 但它不工作......... in oncreteView showSortKeyboard(auto_phone,getActivity()); public static void showSortKeyboard(查看focusedView,Activity活动){ if(focusedView == null){ return; } InputMethodManager imm =(InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(focusedView,InputMethodManager.SHOW_IMPLICIT); } –
我们在onCreate方法中使用了InputManager imgr =(InputMethodManager)getActivity()。getSystemService(Context.INPUT_METHOD_SERVICE); imgr.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT,InputMethodManager.SHOW_FORCED); –
您也可以尝试 getWindow()。setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); – Andy
尝试使用'imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,InputMethodManager.HIDE_IMPLICIT_ONLY);'的情况下,3 –