23.Android 软键盘工具ImeUtil

来源:互联网 时间:1970-01-01

23.Android 软键盘工具ImeUtil

public class ImeUtil { /** * 显示软键盘 * View : EditText、TextView * wantPop : true = show , false = hide * * @param context * @param view * @param wantPop */ public static void popSoftKeyboard(Context context, View view, boolean wantPop) { InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); if (wantPop) { view.requestFocus(); imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT); } else { imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } } /** * 显示软键盘 * * @param view */ public static void showSoftKeyboard(View view) { Context context = view.getContext(); InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); view.requestFocus(); imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT); } /** * 隐藏软键盘 * * @param view */ public static void hideSoftKeyboard(View view) { Context context = view.getContext(); InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); }}

 


相关阅读:
Top