第一种方法
//页面含有文本框,当不点击的时候不会出现键盘,点击后出现键盘
final EditText btn = (EditText)findViewById(R.id.btn);
btn.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
EditText _v=(EditText)v;
if (!hasFocus) {// 失去焦点
_v.setHint(_v.getTag().toString());
isOpenCloseKeyBoard(btn, false);
} else {
String hint=_v.getHint().toString();
_v.setTag(hint);
_v.setHint("");
isOpenCloseKeyBoard(btn, true);
}
}
private void isOpenCloseKeyBoard(EditText btn, boolean b) {
// TODO Auto-generated method stub
}
});
final EditText btn = (EditText)findViewById(R.id.btn);
btn.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
EditText _v=(EditText)v;
if (!hasFocus) {// 失去焦点
_v.setHint(_v.getTag().toString());
isOpenCloseKeyBoard(btn, false);
} else {
String hint=_v.getHint().toString();
_v.setTag(hint);
_v.setHint("");
isOpenCloseKeyBoard(btn, true);
}
}
private void isOpenCloseKeyBoard(EditText btn, boolean b) {
// TODO Auto-generated method stub
}
});
第二种方法
在EditText控件的父容器里面加如这2个属性即可
android:focusable="true"
android:focusableInTouchMode="true"
android:focusableInTouchMode="true"