【问题标题】:android how to set hidden keyboard for an edittextandroid如何为edittext设置隐藏键盘
【发布时间】:2011-10-29 09:48:46
【问题描述】:

在我的应用程序中,我有一个 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);
            }
        });

它不工作。有什么办法吗?

谢谢

【问题讨论】:

    标签: android datepicker


    【解决方案1】:

    怎么样

    EditText et = (EditText)findViewById(R.id.et);
    et.setInputType(InputType.TYPE_NULL);
    

    【讨论】:

    • +1,工作正常!但是当我点击 x 按钮键盘弹出窗口时!
    【解决方案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" />
    

    【讨论】:

      【解决方案3】:

      尝试设置这个

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

      当您的日期选择器退出时,您可能必须再次使其可见,以便您的其他编辑文本应该接收键盘。..

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

      【讨论】:

      • 在editText点击事件中我会给出第一行。我将把第二行放在哪里?
      • 不,它不工作。我试过了,但键盘还是先来,然后是日期选择器
      • 你见过this线程和this问题吗..
      【解决方案4】:

      在 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">
      

      【讨论】:

        猜你喜欢
        • 2014-08-07
        • 2012-02-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-12-14
        相关资源
        最近更新 更多