键盘显示在“ DialogPreference”中.用Textedit键入布局



我对键盘有问题。我已经研究了所有" stackoverflow",我已经测试了数百万种不同的方法。当"对话框"显示时,仍然不能隐藏键盘。可能有人有10000%的工作解决方案吗?

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);}

}

已解决…在XML文档中,在EditText标签的前面,我添加了…

<LinearLayout android:focusable="true"
            android:focusableInTouchMode="true" 
            android:layout_width="0px"
            android:layout_height="0px" />

我已经在这里阅读了。

这是我在项目中实现的方式,此方法将视图如Edittext添加并隐藏软键盘

private void hidesoftKeyboard(View v) {
    InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}

喂我

最新更新