//XML里的
<?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里的
android:theme="@style/demo"
//java代码里的
//点击输入框以外的地方则隐藏输入法
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);
}
}
});