繁体   English   中英

第三方 editText 库中没有 textWatcher 或 setError 方法

[英]There is no textWatcher or setError method on third party editText library

我正在开发一个应用程序,因为我使用可浮动提示编辑文本库。 那个图书馆是

实施 'com.github.thomhurst:ExpandableHintText:1.0.7' 链接:- https://github.com/thomhurst/ExpandableHintText

但是在那里面没有访问一些函数,比如setError()、addOnTextChangeListner()等。现在我能做什么我得不到任何解决方案。 我无法更改库,因为我的应用程序用户界面依赖于此。

感谢您提前回答。

虽然ExpandableHintText小部件本身没有设置错误或文本观察器的方法,但useEditText方法可以使用底层的EditText

这是使用它来设置错误的示例:

yourHintTextWidget.useEditText { editText -> editText.error = "Very wrong, so error, wow" }

请注意,我尚未对此进行测试,只是在源代码中找到了它。

它不会工作,因为该库的开发人员已经创建了从 Frame Layout 扩展的 ExpandableTextHint,您可以查看这个

https://github.com/thomhurst/ExpandableHintText/blob/master/expandablehinttext/src/main/java/com/tomlonghurst/expandablehinttext/ExpandableHintText.kt

所以你可以做的是像这样使用 Material Text Input Layout,

<com.google.android.material.textfield.TextInputLayout
        android:id="@+id/textInputFirstName"
        android:layout_height="wrap_content"
        android:textColorHint="@color/textInputLabelTextColor"
        app:errorEnabled="true"
        app:errorIconDrawable="@drawable/ic_error"
        app:hintTextColor="@color/textInputLabelTextColor"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/userProfilePhoto"
        app:shapeAppearance="?attr/shapeAppearanceSmallComponent">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/inputName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@null"
            android:maxLength="25"
            android:imeOptions="actionDone"
            android:textColor="@color/textInputTextColor" />

    </com.google.android.material.textfield.TextInputLayout>

我知道与那个库相比,这是很多代码,但绝对值得。

您也可以进一步自定义此功能,请查看此官方文档。

https://material.io/components/text-fields/android

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM