更改重点为TextInputLayout的&以编程方式未聚焦的提示颜色 [英] Change TextInputLayout focused & unfocused hint color programmatically
问题描述
我想在处于焦点或未聚焦状态时更改TEXT INPUT LAYOUT中提示的颜色.我有两个TEXT INPUT LAYOUT字段.两个字段都具有相同的颜色.但是处于聚焦状态的颜色出现但未聚焦状态会显示默认的灰色.我想使焦点的颜色在聚焦和未聚焦状态下保持相同.
I wanted to change the color of hint in TEXT INPUT LAYOUT same when it is in focused or unfocused state.i have two TEXT INPUT LAYOUT fields.Both fields are same color.But it in focused state color appears but in an unfocused state the default grey color appears.i want to keep the color color of hint same in both focused and unfocused state.
<com.example.viveka.snipeid.CustomTextInputLayout
android:id="@+id/input_layout_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
app:errorEnabled="true"
>
<EditText
android:id="@+id/editEmail"
android:layout_width="match_parent"
android:layout_height="40dp"
android:hint="email / snipe id"
android:digits="abcdefghijklmnopqrstuvwxyz.@0123456789"
android:textAllCaps="false"
android:textSize="12sp"
android:layout_marginLeft="-4dp"
android:textColor="@color/lightgray"
android:textColorHint="@color/primary"/>
</com.example.viveka.snipeid.CustomTextInputLayout>
期望的图像 我得到的
Expected image what i got
我需要将两个字段都更改为相同的颜色.
i need to change both fields as same color..
推荐答案
您可以这样做.
android:textColorHint="#FF0000"
是EditText的提示颜色.
android:textColorHint="#FF0000"
was EditText's hint color.
如果您想要文本颜色和提示颜色.
If you want the text color as well as the hint color.
您可以在EditText
中更改android:textColor="#FF0000"
.
您可以添加app:errorTextAppearance="@style/text_in_layout_error_hint_Style"
来更改错误文本的颜色.
You can add app:errorTextAppearance="@style/text_in_layout_error_hint_Style"
to change the error text color.
<com.example.viveka.snipeid.CustomTextInputLayout
android:id="@+id/input_layout_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:textColorHint="#FF0000"
app:errorTextAppearance="@style/text_in_layout_error_hint_Style"
app:hintTextAppearance="@style/text_in_layout_hint_Style"
app:errorEnabled="true">
<EditText
android:id="@+id/editEmail"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="-4dp"
android:digits="abcdefghijklmnopqrstuvwxyz.@0123456789"
android:hint="email / snipe id"
android:textAllCaps="false"
android:textColor="#FF0000"
android:textColorHint="@color/primary"
android:textSize="12sp"/>
</com.example.viveka.snipeid.CustomTextInputLayout>
LEFT-TOP
提示颜色取决于app:hintTextAppearance="@style/text_in_layout_hint_Style"
.
以及样式代码:
<style name="text_in_layout_hint_Style">
<item name="android:textColor">#FF0000</item>
<item name="android:textSize">12sp</item>
</style>
添加错误文字样式
<style name="text_in_layout_error_hint_Style">
<item name="android:textColor">#00ff00</item>
<item name="android:textSize">12sp</item>
</style>
像这样: 希望能对您有所帮助.
like this: Hope to help you.
这篇关于更改重点为TextInputLayout的&以编程方式未聚焦的提示颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!