android如何为edittext设置隐藏键盘

时间:2011-10-29 09:48:46

标签: android datepicker

在我的应用程序中,我有一个editText。如果我点击它然后它应该打开日期选择器对话框而不是键盘。 它的开场日期是骑手,但随着键盘也随之而来。

(默认键盘来自editText,但我不想要那个) 我希望这个editText键盘不应该可见/应该被隐藏。

我该怎么做?

我确实喜欢这个,

   private EditText editDate;
  editDate=(EditText)findViewById(R.id.editDate);

editDate.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(editDate.getWindowToken(), 0);

                 showDialog(DATE_DIALOG_ID);
            }
        });

它不起作用。有什么办法吗?

谢谢

4 个答案:

答案 0 :(得分:5)

怎么样?
EditText et = (EditText)findViewById(R.id.et);
et.setInputType(InputType.TYPE_NULL);

答案 1 :(得分:2)

这件事正在发挥作用。 http://developer.android.com/reference/android/view/ViewGroup.html#attr_android:descendantFocusability

<DatePicker
            android:id="@+id/sheduleDatePicker1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:descendantFocusability="blocksDescendants" />

答案 2 :(得分:0)

尝试设置此

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

当您的日期选择器辞职时,您可能必须再次显示它,以便您的其他编辑文本应该接收键盘..

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

答案 3 :(得分:0)

在ActivityLayout xml文件中,将editDate更改为不可编辑。例如,我在我的xml中使用它:

<EditText android:id="@+id/date_EditText"
        android:editable="false"  <---- this is what you want
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:inputType="none" 
        android:layout_weight="2" 
        android:layout_margin="5dp" android:layout_gravity="center_vertical">

相关问题