android AppCompatEditText 自定义下划线颜色

xiaoxiao2021-02-28  101

今天,就讲讲 

AppCompatEditText设置下划线颜色的知识。

如下图所示:

style中添加

</pre><pre name="code" class="html">   <style name="txt_lab" parent="TextAppearance.AppCompat">         <!-- 默认状态提示颜色和字体-->         <item name="android:textColorHint">#8c8c8c</item>         <item name="android:textSize">14sp</item>         <!-- 下面可以根据需要设置,如果没有将默认使用默认theme的颜色 -->         <!-- Label标签的颜色 -->         <item name="colorAccent">#c6174e</item>         <!-- 默认状态状态设置底线颜色 -->         <item name="colorControlNormal">#3F51b5</item>         <!-- 选择的底线颜色 -->         <item name="colorControlActivated">#c6174e</item>     </style>

然后直接使用就可以了。

还可以添加错误提示。

<android.support.design.widget.TextInputLayout             android:id="@+id/til_password"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:theme="@style/txt_lab"             app:errorEnabled="true"             app:errorTextAppearance="@style/txt_lab_msg"             >

            <android.support.v7.widget.AppCompatEditText                 android:id="@+id/acet_password"                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:hint="@string/txt_password"                 />         </android.support.design.widget.TextInputLayout>

    <style name="txt_lab_msg" parent="@android:style/TextAppearance">         <item name="android:textColor">#c6174e</item>         <item name="android:textSize">12sp</item>     </style>

这样,输入错误时就有提示信息。

 android AppCompatEditText 自定义下划线颜色  就讲完了。

就这么简单。

转载请注明原文地址: https://www.6miu.com/read-31153.html

最新回复(0)