我有一个键盘问题。我研究了所有“Stackoverflow”,我测试了数百万种不同的方法。当“Dialog”出现时,仍然无法隐藏键盘。可能有人有10000%的工作解决方案?键盘显示在使用TextEdit的“DialogPreference”类型布局
public class ConfirmDialog extends DialogPreference implements OnClickListener{
public ConfirmDialog(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
setPositiveButtonText(R.string.b_ok);
setNegativeButtonText(R.string.b_cancel);
}
protected View onCreateDialogView(){
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View createdv = inflater.inflate(R.layout.confirm_dialog, null);
//Here I've tried to hide a keyboard!!!!!!!!!!!!!!
((EditText) createdv.findViewById(R.id.confirm_name)).setOnFocusChangeListener(new View.OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus)
{
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
}
// TODO Auto-generated method stub
}
});
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);}
}
好吧,这很容易。 – CrandellWS
@ user922907,谢谢。非常聪明,非常简单。对于SO(上述原始代码示例的所有变体),他在这里没有任何“常规”解决方案似乎适用于DialogPreference布局。 –