如何更改TextinputLayout标签的颜色和edittext下划线android

新手上路,请多包涵

我正在使用 android 设计库的 TextinputLayout 。但无法自定义 EditText 内的 TextinputLayout 的提示颜色、标签颜色和下划线颜色。请帮忙。

原文由 Nitesh Verma 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 968
2 个回答

更改底线颜色:

 <item name="colorControlNormal">#c5c5c5</item>
<item name="colorControlActivated">@color/accent</item>
<item name="colorControlHighlight">@color/accent</item>

有关更多信息,请查看 此线程

浮动时更改提示颜色

<style name="MyHintStyle" parent="@android:style/TextAppearance">
    <item name="android:textColor">@color/main_color</item>
</style>

并像这样使用它:

 <android.support.design.widget.TextInputLayout
    ...
    app:hintTextAppearance="@style/MyHintStyle">

当它不是浮动标签时更改提示颜色:

 <android.support.design.widget.TextInputLayout
    ...
    app:hintTextAppearance="@style/MyHintStyle"
    android:textColorHint="#c1c2c4">

_感谢 @AlbAtNf_

原文由 Pankaj Arora 发布,翻译遵循 CC BY-SA 4.0 许可协议

XML

 <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/activity_profile_textInputLayout_mobile"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="10dp"
        android:layout_marginRight="20dp"
        android:hint="Mobile Number"
        app:theme="@style/EditBoxColor">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/activity_profile_textInputEditText_mobile"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:imeOptions="actionNext"
            android:inputType="number"
            android:maxLength="10"
            android:textSize="15sp" />
    </com.google.android.material.textfield.TextInputLayout>

风格

<style name="EditBoxColor" parent="ShapeAppearance.MaterialComponents.SmallComponent">
    <item name="colorPrimary">@color/colorPurple</item>
    <item name="colorPrimaryDark">@color/colorPurple3</item>
</style>

原文由 Ashwin H 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题