package com.dl7.player.utils;
import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
/**
* SoftInputUtils
*
* @author <a href="http://www.trinea.cn" target="_blank">Trinea</a> 2014-5-07
*/
public class SoftInputUtils {
private SoftInputUtils() {
throw new AssertionError();
}
/**
* 关闭键盘事件.
*
* @param context the context
*/
public static void closeSoftInput(Context context) {
InputMethodManager inputMethodManager = (InputMethodManager) context
.getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputMethodManager != null
&& ((Activity) context).getCurrentFocus() != null) {
inputMethodManager.hideSoftInputFromWindow(((Activity) context)
.getCurrentFocus().getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
}
}
/**
* 弹出输入法
*
* @param context context
* @param view 编辑控件
*/
public static void setEditFocusable(final Context context, final View view) {
view.setFocusableInTouchMode(true);
view.requestFocus();
InputMethodManager inputMethodManager = (InputMethodManager) context
.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.showSoftInput(view, 0);
}
}