importjava.util.Timer;importjava.util.TimerTask;importandroid.content.Context;importandroid.view.View;importandroid.view.inputmethod.InputMethodManager;importandroid.widget.EditText;public classInputTools {//隐藏虚拟键盘
public static voidHideKeyboard(View v)
{
InputMethodManager imm=( InputMethodManager ) v.getContext( ).getSystemService( Context.INPUT_METHOD_SERVICE );if( imm.isActive( ) ) {
imm.hideSoftInputFromWindow( v.getApplicationWindowToken( ) ,0);
}
}//显示虚拟键盘
public static voidShowKeyboard(View v)
{
InputMethodManager imm=( InputMethodManager ) v.getContext( ).getSystemService( Context.INPUT_METHOD_SERVICE );
imm.showSoftInput(v,InputMethodManager.SHOW_FORCED);
}//强制显示或者关闭系统键盘
public static void KeyBoard(final EditText txtSearchKey,finalString status)
{
Timer timer= newTimer();
timer.schedule(newTimerTask(){
@Overridepublic voidrun()
{
InputMethodManager m=(InputMethodManager)
txtSearchKey.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);if(status.equals("open"))
{
m.showSoftInput(txtSearchKey,InputMethodManager.SHOW_FORCED);
}else{
m.hideSoftInputFromWindow(txtSearchKey.getWindowToken(),0);
}
}
},300);
}//通过定时器强制隐藏虚拟键盘
public static void TimerHideKeyboard(finalView v)
{
Timer timer= newTimer();
timer.schedule(newTimerTask(){
@Overridepublic voidrun()
{
InputMethodManager imm=( InputMethodManager ) v.getContext( ).getSystemService( Context.INPUT_METHOD_SERVICE );if( imm.isActive( ) )
{
imm.hideSoftInputFromWindow( v.getApplicationWindowToken( ) ,0);
}
}
},10);
}//输入法是否显示着
public static booleanKeyBoard(EditText edittext)
{boolean bool = false;
InputMethodManager imm=( InputMethodManager ) edittext.getContext( ).getSystemService( Context.INPUT_METHOD_SERVICE );if( imm.isActive( ) )
{
bool= true;
}returnbool;
}
}