首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

掩藏输入法

2012-08-07 
隐藏输入法private void hideIM(View edt){?// try to hide input_method:try {InputMethodManager im (

隐藏输入法

private void hideIM(View edt){

?

// try to hide input_method:

try {

InputMethodManager im = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);

?

IBinder windowToken = edt.getWindowToken();

if(windowToken != null) {

?

// always de-activate IM

im.hideSoftInputFromWindow(windowToken, 0);

}

?

} catch (Exception e) {

Log.e("HideInputMethod", "failed:"+e.getMessage());

}

}

private OnFocusChangeListener focus_listener_noIM = new OnFocusChangeListener(){

?

@Override

public void onFocusChange(View v, boolean hasFocus) {

if (hasFocus==true) {

hideIM(v);

}

}

};

?

private OnTouchListener touch_listener_noIM = new OnTouchListener(){

?

@Override

public boolean onTouch(View v, MotionEvent event) {

if(event.getAction()==MotionEvent.ACTION_DOWN) {

hideIM(v);

}

return false; // dispatch the event further!

}

};

?

// 以下是Activity的onCreate()函数的片断:

public void onCreate(Bundle savedInstanceState) {

?

EditText edt_url = (EditText)findViewById(R.id.edt_url);

edt_url.setOnFocusChangeListener(focus_listener_noIM);

edt_url.setOnTouchListener(touch_listener_noIM);

}

热点排行