简体   繁体   English

在TextInputLayout中使用MaterialEditText是一个好主意吗

[英]Is it a good idea to use MaterialEditText within a TextInputLayout

I am implementing a password field that displays the count of characters while the user types like ("3/8+"). 我正在实现一个密码字段,该字段在用户键入(“ 3/8 +”)时显示字符数。 This is provided by MaterialEditText library . 这是由MaterialEditText库提供的。

I also want to allow the user to hide/show the password, and this is provided by Android's TextInputLayout . 我还希望允许用户隐藏/显示密码,这是由Android的TextInputLayout提供

I am currently using both, but when I click on the eye icon, the error message of the EditText blinks once (probably because the error message should be handle at the TextInputLayout level, not the EditText level). 我当前同时使用这两种方法,但是当我单击眼睛图标时,EditText的错误消息闪烁一次(可能是因为该错误消息应该在TextInputLayout级别而不是EditText级别处理)。 Whatever this is caused by, it makes me wonder if it is a good idea to use MaterialEditText within a TextInputLayout. 无论是什么原因引起的,这让我想知道在TextInputLayout中使用MaterialEditText是否是一个好主意。

I feel like TextInputLayout pushes a lot of responsibility outside of the EditText towards the TextInputLayout, which may cause conflicts with MaterialEditText. 我觉得TextInputLayout将EditText之外的很多职责推向了TextInputLayout,这可能会导致与MaterialEditText发生冲突。

Should I drop MaterielEditText in that situation ? 在这种情况下我应该放弃MaterielEditText吗?

I always prefeer to use Android SDK components, and what you need is ok with: 我总是喜欢使用Android SDK组件,并且您可以使用以下工具:

<android.support.design.widget.TextInputLayout
        android:id="@+id/input_layout_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <EditText
            android:id="@+id/input_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:hint="@string/hint_name" />
</android.support.design.widget.TextInputLayout>

You can add the eye component for working with this kind of EditText without problem. 您可以毫无问题地添加用于处理这种EditText的eye组件。

You don't have to use another library for what you need. 您无需使用其他库来满足需要。 When you use another library, there are lots of possibility to have much bugs as using SDK component. 当您使用另一个库时,使用SDK组件很可能会出现很多错误。

Just use a Third Party Library when you really think that you need for your porpuse. 当您真正认为自己需要用时,只需使用第三方库。

Nice coding! 不错的编码!

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

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