键盘在带有TextEdit的“DialogPreference”类型布局中显示

时间:2014-01-24 15:54:46

标签: android dialog-preference

我的键盘有问题。我研究了所有的“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);}

}

2 个答案:

答案 0 :(得分:2)

...解决 在EditText标记前面的XML文档中,我添加了...

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

我读过它here

答案 1 :(得分:1)

这是我如何在我的项目中实现它这个方法采取类似edittext的视图并隐藏软键盘

private void hidesoftKeyboard(View v) {

    InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(v.getWindowToken(), 0);

}

喂我回来