http://blog.csdn.net/cwc455826074/article/details/6883467
XML里的
[html] view plain copy <?xml version="1.0" encoding="utf-8"?> <resources xmlns:android="http://schemas.android.com/apk/res/android"> <style name="demo" parent="android:Theme"> <item name="android:focusableInTouchMode">true</item> </style> </resources>
//AnroidMainifest里的
[html] view plain copy android:theme="@style/demo"//Java代码里的
[html] view plain copy //点击输入框以外的地方则隐藏输入法 addfoodweight.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { // TODO Auto-generated method stub if (!hasFocus) { System.out.println("失去焦点"); // 失去焦点 addfoodweight.clearFocus(); InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(addfoodweight.getWindowToken(), 0); } } });