当前位置: 首页 > 知识库问答 >
问题:

禁用文本输入布局的错误文本提示或更改edittext下划线颜色

施令秋
2023-03-14

共有1个答案

唐威
2023-03-14

因此,我认为禁用错误提示是不可能的(我可能错得很严重)。处理此问题的最佳方法是使用setSupportBackgroundTintList或SetBackgroundTintList更改editText中行的颜色。

几件关键的事情。

1)如果您使用的是SDKVersion23或更高版本,那么可以使用常规editText和setBackgroundTintList方法。

我的布局中的AppCompatEditText。

<android.support.design.widget.TextInputLayout
        android:id="@+id/login_user_password_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="16sp"
        android:hint="@string/login_hint_password"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@id/login_user_email_layout"
        app:layout_constraintBottom_toTopOf="@id/error_text"
        app:layout_constraintRight_toRightOf="parent">

        <android.support.v7.widget.AppCompatEditText
            android:id="@+id/login_user_password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPassword"
            android:imeOptions="actionDone"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="30dp"/>

</android.support.design.widget.TextInputLayout>

方法设置下划线颜色。

@SuppressLint("RestrictedApi")
private void setEditTextFields(){
    if(errorLoginIn){
        errorLoginIn = false;
        binding.errorText.setVisibility(View.VISIBLE);
        binding.loginUserEmail.setSupportBackgroundTintList(getResources().getColorStateList(R.color.colorError));
        binding.loginUserPassword.setSupportBackgroundTintList(getResources().getColorStateList(R.color.colorError));
    }else{
        binding.errorText.setVisibility(View.INVISIBLE);
        binding.loginUserEmail.setSupportBackgroundTintList(getResources().getColorStateList(R.color.primaryColor));
        binding.loginUserPassword.setSupportBackgroundTintList(getResources().getColorStateList(R.color.primaryColor));
    }
}

绑定是布局,因为我使用的是数据绑定。

 类似资料:
  • 嗨,我在我的应用程序中使用TextInputLayout。我想将提示文本颜色和浮动标签颜色(聚焦和不聚焦)设置为白色。我已经尝试了下面的代码。 它适用于Lollipop,但不适用于较低的versions.How我可以在较低的版本中实现相同的功能吗?

  • 我正在使用新的谷歌设计库(com . Android . support:design:22 . 2 . 0 ),我在使用Android . support . design . widget . textinputlayout时遇到了问题。 如果我以编程方式设置它的EditText,浮动提示颜色是灰色而不是强调色。如果用户自己填充字段(EditText)或者如果他改变字段的预定义值,它就工作。

  • 启用这些后,我需要提示以不同的颜色显示,如下所示 当我这样尝试时,效果很好 问题是,我必须使用来显示浮动提示。所以,当我在中添加时,这段代码根本不起作用。我用尝试了很多东西,如下所示。但没有任何效果。我只需要EditText的提示文本颜色(不是浮动提示文本)在启用时应该是一种颜色,在禁用时,在中使用时应该是不同的颜色。请帮助! 注意:我的问题不是这个问题的重复。在那里,它提到了TextInputL

  • 我对这两个都不熟悉 在我所有的表单中,textField的下划线都显示为蓝色。我想把它换成其他颜色。我使用的代码就像。。。 无法理解如何实现这一点。 注意:我知道这里有一个类似的问题,在flifter中更改TextField的下划线。但是,在那里也没有完全解决。另外,还有一个链接看起来与我的类似,它在这里使用appcompat v7更改EditText底线颜色,但实际上是属于Android开发的,

  • 我试图改变一个文本字段的下划线颜色时,它的非活动/不集中。我不确定在哪里进行此更改,输入装饰主题仅在选中时更改下划线颜色。我如何实现这一点? 我试图改变这种颜色文本字段为浅灰色时,它没有选择/失去焦点。

  • 不确定我遗漏了什么,但每次聚焦时,下划线颜色都不适合我设置的自定义颜色。这里是我的主题代码供参考 如您所见,我已将它们全部设置为白色,但不知何故,当聚焦时,下划线变为绿色 这是我的代码从布局