下面列出了android.view.inputmethod.InputMethodManager#showSoftInput ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* We override this method to be sure and show the soft keyboard if
* appropriate when the TextView has focus.
*/
@Override
public void onWindowFocusChanged(boolean hasWindowFocus) {
super.onWindowFocusChanged(hasWindowFocus);
if (hasWindowFocus && mSearchView.hasFocus() && getVisibility() == VISIBLE) {
InputMethodManager inputManager = (InputMethodManager) getContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(this, 0);
// If in landscape mode, then make sure that
// the ime is in front of the dropdown.
if (isLandscapeMode(getContext())) {
ensureImeVisible(this, true);
}
}
}
public static void showKeyboard(View view) {
InputMethodManager inputMethodManager
= (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputMethodManager != null) {
inputMethodManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
}
}
@Override public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
// Make sure this view is focused
editText.requestFocus();
// Show keyboard
InputMethodManager inputMethodManager = (InputMethodManager) getContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.showSoftInput(editText, 0);
return true;
}
return super.onTouchEvent(event);
}
/**
* 显示输入法
* @param context
* @param view
*/
public static void showInputSoftFromWindowMethod(Context context,View view){
try {
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(view, InputMethodManager.SHOW_FORCED);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void showKeyboard(Context context, View view) {
view.requestFocus();
InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputMethodManager != null) {
inputMethodManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
}
}
/**
* editeText获取键盘
*
* @param et
*/
public static void getEditFocus(android.widget.EditText et) {
et.setFocusableInTouchMode(true);
et.requestFocus();
InputMethodManager inputManager = (InputMethodManager) et.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(et, 0);
}
public static void showKeyboard(final View view) {
view.requestFocus();
InputMethodManager inputManager =
(InputMethodManager) view.getContext().getSystemService(
Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(view, 0);
}
/**
* Shows soft keyboard and requests focus for given view.
*/
public static void showSoftKeyboard(Context context, View view) {
if (view == null) {
return;
}
final InputMethodManager manager = (InputMethodManager)
context.getSystemService(Context.INPUT_METHOD_SERVICE);
view.requestFocus();
manager.showSoftInput(view, 0);
}
public void setFoucus(View view){
// 获取 接受焦点的资格
view.setFocusable(true);
// 获取 焦点可以响应点触的资格
view.setFocusableInTouchMode(true);
// 请求焦点
view.requestFocus();
// 弹出键盘
InputMethodManager manager=(InputMethodManager)view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
manager.toggleSoftInput(0,0);
manager.showSoftInput(view,0);
}
private static void showSoftInputUnchecked(View view, InputMethodManager imm, int flags) {
try {
Method method = imm.getClass().getMethod("showSoftInputUnchecked", int.class, ResultReceiver.class);
method.setAccessible(true);
method.invoke(imm, flags, null);
} catch (Exception e) {
//Fallback to public API which hopefully does mostly the same thing
imm.showSoftInput(view, flags);
}
}
private void showInputMethod(EditText editTextMessage) {
editTextMessage.requestFocus();
//如果已经显示,则继续操作时不需要把光标定位到最后
if (!isKeyboardShowed) {
editTextMessage.setSelection(editTextMessage.getText().length());
isKeyboardShowed = true;
}
InputMethodManager imm = (InputMethodManager) container.activity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editTextMessage, 0);
container.proxy.onInputPanelExpand();
}
@Override
protected void onDialogShown() {
updatePosButton();
if (getArguments().getBoolean(FILTER)){
// show keyboard
InputMethodManager imm = (InputMethodManager) getActivity()
.getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.showSoftInput(mFilterEditText, InputMethodManager.SHOW_IMPLICIT);
}
}
}
/**
* Helper for opening the soft keyboard
*/
public void openKeyboard(){
InputMethodManager imm = (InputMethodManager) getActivity()
.getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.showSoftInput(mInput, InputMethodManager.SHOW_IMPLICIT);
}
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
if (searchBox != null) {
InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(searchBox, InputMethodManager.SHOW_IMPLICIT);
}
}
/**
* 动态显示软键盘
*/
public static void showSoftInput(Context context, EditText edit) {
edit.setFocusable(true);
edit.setFocusableInTouchMode(true);
edit.requestFocus();
InputMethodManager inputManager = (InputMethodManager) context
.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(edit, 0);
}
public void openFromSearch() {
fromEditText.requestFocus();
InputMethodManager imm =(InputMethodManager)
getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(fromEditText, InputMethodManager.SHOW_IMPLICIT);
listener.onDirectionFromQueryChange("");
}
/**
* 显示软键盘
* @param v
*/
public static void ShowKeyboard(View v) {
InputMethodManager imm = (InputMethodManager) v.getContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(v, InputMethodManager.SHOW_FORCED);
}
public static boolean showSoftInput(View view) {
InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
return imm.showSoftInput(view, InputMethodManager.SHOW_FORCED);
}
private void showAddFilterDialog(final FilterAdapter filterAdapter) {
// show a popup to add a new filter text
LayoutInflater inflater = getLayoutInflater();
@SuppressLint("InflateParams")
final AutoCompleteTextView editText =
(AutoCompleteTextView) inflater.inflate(R.layout.dialog_new_filter, null, false);
// show suggestions as the user types
List<String> suggestions = new ArrayList<>(mSearchSuggestionsSet);
SortedFilterArrayAdapter<String> suggestionAdapter = new SortedFilterArrayAdapter<>(
this, R.layout.list_item_dropdown, suggestions);
editText.setAdapter(suggestionAdapter);
final MaterialDialog alertDialog = new MaterialDialog.Builder(this)
.title(R.string.add_filter)
.positiveText(android.R.string.ok)
.onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
handleNewFilterText(editText.getText().toString(), filterAdapter);
dialog.dismiss();
}
})
.negativeText(android.R.string.cancel)
.customView(editText, true)
.build();
// when 'Done' is clicked (i.e. enter button), do the same as when "OK" is clicked
editText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
// dismiss soft keyboard
handleNewFilterText(editText.getText().toString(), filterAdapter);
alertDialog.dismiss();
return true;
}
return false;
}
});
alertDialog.show();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, 0);
}
/**
* 打开软键盘
*
* @param mEditText 输入框
* @param mContext 上下文
*/
public static void openKeyboard(EditText mEditText, Context mContext) {
InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(mEditText, InputMethodManager.RESULT_SHOWN);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
}