[英]Change TextInputLayout focused & unfocused hint color programmatically
我想在 TEXT INPUT LAYOUT 處於聚焦或未聚焦狀態時將提示的顏色更改為相同。我有兩個 TEXT INPUT LAYOUT 字段。兩個字段顏色相同。但它在聚焦狀態下出現顏色,但默認處於未聚焦狀態出現灰色。我想在聚焦和未聚焦狀態下保持提示的顏色相同。
<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>
我想在處於焦點或未聚焦狀態時更改TEXT INPUT LAYOUT中的提示顏色。我有兩個TEXT INPUT LAYOUT字段。兩個字段都是相同的顏色。出現灰色。我想使提示的顏色在聚焦和未聚焦狀態下保持相同。
<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>
我需要將兩個字段都更改為相同的顏色。
我想在處於焦點或未聚焦狀態時更改TEXT INPUT LAYOUT中的提示顏色。我有兩個TEXT INPUT LAYOUT字段。兩個字段都是相同的顏色。出現灰色。我想使提示的顏色在聚焦和未聚焦狀態下保持相同。
<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>
我需要將兩個字段都更改為相同的顏色。
我想在處於焦點或未聚焦狀態時更改TEXT INPUT LAYOUT中的提示顏色。我有兩個TEXT INPUT LAYOUT字段。兩個字段都是相同的顏色。出現灰色。我想使提示的顏色在聚焦和未聚焦狀態下保持相同。
<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>
我需要將兩個字段都更改為相同的顏色。
您可以通過使用材質 TextInputLayout 並添加 textColorHint 、 hintTextColor 屬性來簡單地做到這一點,這非常有效
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="@color/gray"
app:hintTextColor="@color/gray"
>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.