[英]how to change TextInputLayout error color and Text size of Error dynamically with code
[英]Custom TextInputLayout's error BACKGROUND color
是否可以将TextInputLayout
错误的Background颜色更改,而不是将文本从透明更改为红色?
在style.xml中创建样式
<style name="error_appearance" parent="@android:style/TextAppearance">
<item name="android:textColor">@color/red_500</item>
<item name="android:textSize">12sp</item>
</style>
并在您的TextInputLayout小部件中使用它:
<android.support.design.widget.TextInputLayout
android:id="@+id/emailInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:errorTextAppearance="@style/error_appearance">
在gradle中添加最新的材料依存关系并使用setError
compile 'com.android.support:design:25.0.0'
emailInputLayout =(TextInputLayout)findViewbyId(R.id.emailInputLayout);
Spannable errorMsg = new SpannableString("Email cannot be Empty ");
errorMsg.setSpan(new ForegroundColorSpan(Color.BLUE), 0, errorMsg.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
errorMsg.setSpan(new BackgroundColorSpan(Color.WHITE), 0, errorMsg.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
emailInputLayout.setError(errorMsg);
这很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.