【问题标题】:Can't change hint's color in TextInputLayout无法在 TextInputLayout 中更改提示的颜色
【发布时间】:2015-10-22 23:40:44
【问题描述】:

我想将 TextInputLayout 中可见提示的颜色设置为我的自定义颜色(蓝色)。不幸的是,到目前为止我所取得的成就是:

如何以我的自定义颜色设置提示样式?

这就是我到目前为止所做的:

styles.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/police_blue</item>
        <item name="colorPrimaryDark">@color/police_blue_dark</item>
        <item name="colorAccent">@color/police_blue_light</item>

        <item name="android:textColorHint">@color/police_blue_light</item>
        <item name="colorControlNormal">@color/police_blue_light</item>
        <item name="colorControlActivated">@color/police_blue_light</item>
        <item name="colorControlHighlight">@color/police_blue_light</item>
    </style>

layout_file.xml

<android.support.design.widget.TextInputLayout
        android:id="@+id/login_username_wrapper"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/login_username"
            android:hint="@string/username_hint"
        />
    </android.support.design.widget.TextInputLayout>

【问题讨论】:

  • @TristanWiley 您发布的问题中的所有解决方案都不适合我。我都试过了……
  • 只需在&lt;EditText 标签中添加android:textColorHint="@color/yourColor" 或在&lt;TextInputLayout 中添加此android:textColorHint="@color/yourColor"

标签: android android-layout android-styles android-textinputlayout


【解决方案1】:

应用android:background="@drawable/edittext_bg" 在你的布局上

    <EditText
        android:la`enter code here`yout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/login_username"
        android:hint="@string/username_hint"
    />

在drawable下创建文件edittext_bg.xml并将这段代码放在里面。

<layer-list>
   <item>
    <shape android:shape="rectangle">
        <!-- Draw a 2dp width border around shape -->
        <stroke`android:color="#ff1e0c"`
           android:width="2dp"
            />
    </shape>
</item>
<!-- Overlap the left, top and right border using background color  -->
<item android:bottom="2dp">
    <shape android:shape="rectangle">
        <solid android:color="#fffbce"/>
    </shape>
</item>

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 2020-06-05
    • 2015-08-29
    • 2015-09-15
    • 2015-08-15
    • 1970-01-01
    • 2018-11-03
    • 2020-07-02
    • 1970-01-01
    相关资源
    最近更新 更多