我希望TextInputLayouts的浮動標籤在出現錯誤時更改顏色(例如,變爲紅色)。我可以更改錯誤文本的顏色,但它對浮動標籤的外觀沒有影響(不像其他某個其他線索聲稱的那樣)。我無法使用提示顏色的選擇器來解決這個問題,因爲似乎沒有爲錯誤定義的狀態。有沒有人有任何想法如何做到這一點,而不必手動編程錯誤事件的變化/創建一個新的Java類(與EditText作爲父)?Android:在錯誤狀態下更改TextInputLayout中浮動標籤(提示)的顏色
這裏是我所定義的兩種風格:
<style name="EditTextFloatingLabel" parent="@android:style/TextAppearance">
<item name="android:textSize">@dimen/textsize_caption_small</item>
<item name="android:layout_marginBottom">8dp</item>
<item name="android:textColor">@color/input_text_color</item>
</style>
<style name="EditTextErrorText" parent="@android:style/TextAppearance">
<item name="android:textColor">@color/error_color</item>
</style>
<style name="EditTextLayout">
<item name="android:textColorHint">@color/placeholder_color</item>
<item name="android:background">@drawable/input_field_background</item>
<item name="android:paddingBottom">@dimen/default_margin_bottom</item>
<item name="android:paddingStart">@dimen/default_margin_left</item>
<item name="android:paddingEnd">@dimen/default_margin_right</item>
</style>
<style name="EditTextTheme">
<item name="android:imeOptions">actionDone</item>
<item name="android:maxLines">1</item>
<item name="colorControlNormal">@color/primary_line_color</item>
<item name="colorControlActivated">@color/nordea_blue</item>
<item name="android:colorControlHighlight">@color/error_color</item>
<item name="android:textColorPrimary">@color/input_field_text</item>
<item name="android:textSize">@dimen/textsize_caption</item>
<item name="android:textColorHint">@color/placeholder_color</item>
</style>
<style name="EditText">
<item name="android:theme">@style/EditTextTheme</item>
<item name="android:textCursorDrawable">@drawable/cursor_blue</item>
<item name="android:paddingTop">@dimen/default_padding_top</item>
<item name="android:paddingStart">@dimen/payment_text_input_padding</item>
</style>
用法:
<android.support.design.widget.TextInputLayout
android:id="@+id/input_field_error_wrapper_light"
style="@style/EditTextLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/testlogin_text_input_end_padding"
android:layout_marginStart="@dimen/testlogin_text_input_start_padding"
android:paddingTop="@dimen/default_padding_top"
app:hintTextAppearance="@style/EditTextFloatingLabel"
app:errorTextAppearance="@style/EditTextErrorText"
app:errorEnabled="true">
<EditText
android:id="@+id/input_field_light_error"
style="@style/EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#Input Field Disabled Light"
android:imeOptions="actionDone"
/>
</android.support.design.widget.TextInputLayout>
這是我所看到的:
嘗試我的更新回答 –