【问题标题】:Avoid edittext getting focus when text changes避免edittext在文本更改时获得焦点
【发布时间】:2012-09-25 05:28:02
【问题描述】:

我有一个带有加号和减号按钮和一个编辑文本的数字选择器。

用户在点击edittext时可以点击加减号按钮进行增减或手动输入。

但每次用户单击 +/- 按钮时,文本都会发生变化,并且 edittext 会获得焦点。 这意味着边框改变颜色并且光标出现。

我想避免这种情况,我该怎么做?

我尝试将 clearFocus() 添加到 onTextChanged 侦听器,这可行,但边框仍然会暂时改变颜色。

【问题讨论】:

  • edittext中的文字怎么设置? (还有,focusable="false"?)

标签: android


【解决方案1】:

在您拥有 editText 的 XML 文件中,您可以将 focusable 设置为 false:

 android:focusable="false"

要手动显示键盘,请使用:

InputMethodManager inputManager = (InputMethodManager)
            getSystemService(Context.INPUT_METHOD_SERVICE); 
    try{
    inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),
               InputMethodManager.SHOW_FORCED);
    }
    catch (Exception e)
    {}

然后把它放在一个监听器上。

【讨论】:

  • 这是我想要的,但我也希望在用户点击编辑文本时显示键盘。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-30
  • 2014-03-05
  • 1970-01-01
  • 1970-01-01
  • 2018-02-10
相关资源
最近更新 更多