android - 带有可点击链接的EditText,除非用户自行更改它,否则不可编辑/Kotlin,Android

标签 android kotlin hyperlink android-edittext

我正在尝试改善我的ToDoList应用。
我想将我的EditText放在不可编辑字段中,以便用户可以使用他保存的链接,例如在以前的应用程序使用中。如果用户希望编辑该字段以将其保存到数据库中,则可以通过按下按钮或双击或任何其他方式来“激活”编辑。

那是我在这里的第一个问题,所以我希望我没有违反任何规则
谢谢建议

 <EditText
        android:id="@+id/taskDescEV"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="16dp"
        android:layout_marginBottom="16dp"
        android:autoLink="web"
        android:background="@drawable/task_row_background"
        android:enabled="true"
        android:gravity="start|top"
        android:hint="@string/taskDescTV_hint"
        android:inputType="textMultiLine|text"
        android:linksClickable="true"
        android:paddingStart="12dp"
        android:paddingTop="8dp"
        android:paddingEnd="8dp"
        android:paddingBottom="8dp"
        android:textColor="@color/text_color"
        android:textColorHint="@color/hint_color"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="@+id/saveBtn"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/taskNameEV" />


@InternalCoroutinesApi
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)

    navController = Navigation.findNavController(view)
    taskViewModel = ViewModelProvider(this).get(TaskViewModel::class.java)
    val oldTaskName = args.itemName
    val oldTaskDesc = args.itemDesc
    taskNameEV.requestFocus()
    taskNameEV.setText(oldTaskName)
    taskDescEV.setText(oldTaskDesc)
    showKeyboard()

    taskDescEV.isEnabled = false



    saveBtn.setOnClickListener {

        if (taskNameEV.text.isNotEmpty()) {
            hideKeyboard()
            Handler().postDelayed(
                {
                    val taskNewName = taskNameEV.text.toString().capitalize(Locale.ROOT)
                    val taskNewDesc = taskDescEV.text.toString()
                    val oldTask = Task(oldTaskName, oldTaskDesc)
                    val newTask = Task(taskNewName, taskNewDesc)
                    taskViewModel.edit(oldTask, newTask)



                    navController!!.navigate(R.id.action_editFragment_to_listFragment)
                }, 300
            )


        } else {
            Toast.makeText(activity, "You can't add empty task", Toast.LENGTH_LONG).show()
        }
    }
}

最佳答案

EditTextView。可以启用或禁用它。

假设您的EditText的名称为editText:
editText.setEnabled(false)将禁用对其的编辑。

编辑:
将它们添加到您的布局:

android:autoLink="web"
android:linksClickable="true"

关于android - 带有可点击链接的EditText,除非用户自行更改它,否则不可编辑/Kotlin,Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61478045/

相关文章:

android - 如何在有空间的情况下执行繁重的数据库操作?

android - "The specified child already has a parent. You must call removeView() on the child' s parent first”第二次创建AlertDialog

css - 如何应用不同风格的链接?

knockout.js - KnockoutJS 中的 Href 和 mailto 链接

android - 使用带有 Room 的 ForeignKey 的墓碑

android - 将wifi SSID与c++中的字符串进行比较

kotlin - 如何用正则表达式替换 Kotlit 中的First?

javascript - 如何将目标 ="_blank"添加到指定 div 中的链接?

java - 使用 java DocumentBuilder 从 xml feed 获取 rel ="alternate"href 值

android - Facebook Android 登录屏幕 WebViewCoreThread 由于未捕获的异常而退出