2014-01-24 96 views
1

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

}

回答

2

解决... 在XML文档正好在EditText标签前面添加...

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

我读过它here

+0

好吧,这很容易。 – CrandellWS

+0

@ user922907,谢谢。非常聪明,非常简单。对于SO(上述原始代码示例的所有变体),他在这里没有任何“常规”解决方案似乎适用于DialogPreference布局。 –

1

这个我怎么在我的项目实现它这个方法采取类似的EditText视图,并隐藏软键盘

private void hidesoftKeyboard(View v) { 

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

} 

喂我回来

+0

我试过...不工作... InputMethodManager imm =(InputMethodManager)getContext()。getSystemService(Context.INPUT_METHOD_SERVICE); – user922907

+0

你可以发布你的布局和全面实施吗?我可以帮你吗 –

+0

我不能在这里添加代码。太长和太多的错误。 Stackoverflow不允许。 – user922907