在使用TextInputLayout时,可以通过设置TextInputLayout的setErrorTextColor()方法来保持浮动或出错时的提示颜色与错误颜色不同。
具体步骤如下:
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter text" />
</com.google.android.material.textfield.TextInputLayout>
TextInputLayout textInputLayout = findViewById(R.id.textInputLayout);
textInputLayout.setErrorTextColor(ColorStateList.valueOf(Color.RED));
textInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(Color.BLUE));
这样,当输入内容出错时,错误提示文字的颜色将会是红色,而浮动提示文字的颜色将会是蓝色。
推荐的腾讯云相关产品:腾讯云移动推送(https://cloud.tencent.com/product/umeng_push)可以用于移动应用的消息推送,提供了丰富的消息推送功能和统计分析能力,适用于各类移动应用场景。
领取专属 10元无门槛券
手把手带您无忧上云