【问题标题】:EditText stops being focusable after changing and then reseting attributesEditText 在更改然后重置属性后停止可聚焦
【发布时间】:2021-10-24 04:17:38
【问题描述】:

在我的项目中,我将 Edittexts 伪装成文本视图,用户只能在启用编辑模式后进行编辑。我为此设置了2个扩展功能

private fun EditText.disguiseAsTextview() {
    this.isCursorVisible = false
    this.isLongClickable = false
    this.isClickable = false
    this.isFocusable = false
    this.isSelected = false
    this.setBackgroundResource(android.R.color.transparent)
}

private fun EditText.breakDisguise() {
    this.isCursorVisible = true
    this.isLongClickable = true
    this.isClickable = true
    this.isFocusable = true
    this.background = editTextDrawableBackground
}

一开始 EditText 按预期工作,但在伪装和不伪装之后,EditText 无法再被聚焦,并闪烁蓝色,就好像它被选中了一瞬间。不知道为什么会发生这种情况,调用breakDisguise后一切都恢复到默认状态。

【问题讨论】:

    标签: android kotlin android-edittext


    【解决方案1】:

    在您的 breakDisguise 方法中,

    替换

    this.isFocusable = true
    

    this.isFocusableInTouchMode = true
    

    【讨论】:

      猜你喜欢
      • 2015-01-07
      • 2013-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-24
      • 1970-01-01
      • 2014-06-18
      • 2016-04-11
      相关资源
      最近更新 更多