【问题标题】:TextInputLayout hint colorTextInputLayout 提示颜色
【发布时间】:2015-08-15 21:07:52
【问题描述】:

我正在使用新的 Google 设计库 (com.android.support:design:22.2.0),但 android.support.design.widget.TextInputLayout 有问题。

如果我以编程方式设置其 EditText,则浮动提示颜色为灰色而不是强调色。如果用户自己填写字段 (EditText) 或更改字段的预定义值,它就会起作用。

这是我的代码:

<android.support.design.widget.TextInputLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent">
        <EditText
            android:id="@+id/register_username"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/register_username"
            android:inputType="text"/>
</android.support.design.widget.TextInputLayout>

用户单击某个按钮后,它会通过 EditText 的 setText() 方法填充字段,并且浮动提示变为灰色。是错误还是我遗漏了什么?

【问题讨论】:

  • 请查看我的answer here 更改您选择的标签颜色

标签: android android-edittext android-design-library


【解决方案1】:

android:textColorHint="@color/your_color" 放入TextInputLayout

【讨论】:

    【解决方案2】:

    以下代码对我有用:

    <android.support.design.widget.TextInputLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_marginTop="16dp">
    
             <EditText
                  android:id="@+id/email"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:background="@drawable/white_box"
                  android:hint="@string/prompt_email"
                  android:inputType="textEmailAddress"
                  android:maxLines="1"
                  android:singleLine="true"
                  android:textColor="@color/text_color"
                  android:textColorHighlight="@color/text_color"
                  android:textColorHint="@color/text_color"
                  android:drawableRight="@drawable/ic_action_email"/>
     </android.support.design.widget.TextInputLayout>
    

    textColorHintedittext 未聚焦时的提示颜色和 android:textColorHighlight浮动模式下的提示颜色

    【讨论】:

      【解决方案3】:

      使用 android.support.v7.widget.AppCompatEditText 而不是 EditText,您的问题应该会得到解决。还要确保您的 gradle 设置如下:

      compile 'com.android.support:appcompat-v7:22.2.0'
      compile 'com.android.support:support-v4:22.2.0'
      compile 'com.android.support:design:22.2.0'
      

      【讨论】:

      • 对于最新的支持库,这应该不再需要了。
      • 正确,这个问题是在我们第一次得到 TextInputLayout 的时候提出的
      【解决方案4】:

      here

      特别是android.support.design:hintTextAppearance="@style/TextAppearance.AppCompat"&gt;

      【讨论】:

      • 提示颜色没问题,只有当我以编程方式将文本设置为 EditText 时它才会损坏。我认为它应该自动成为强调色。我尝试了这个解决方法,但我不喜欢这个解决方案:-)
      • 我试过了,没用。调用 setText 方法后仍然提示变灰。
      猜你喜欢
      • 2020-06-05
      • 1970-01-01
      • 2021-06-21
      • 2018-03-21
      • 2015-08-29
      • 1970-01-01
      • 2018-11-03
      • 2015-09-15
      相关资源
      最近更新 更多