package com.electric.chargingpile.util; import android.app.Activity; import android.view.WindowManager; import android.widget.EditText; /** * Created by demon on 2017/8/23. */ public class SoftInputUtil { /** * EditText获取焦点并显示软键盘 */ public static void showSoftInputFromWindow(Activity activity, EditText editText) { editText.setFocusable(true); editText.setFocusableInTouchMode(true); editText.requestFocus(); activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); // imm = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE); } public static void hideSoftInputFromWindow(Activity activity) { activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); } }