如何更改TextInputLayout的提示文本颜色

6

你好,我在我的应用程序中使用了TextInputLayout。我希望将提示文本颜色和浮动标签颜色(包括聚焦和未聚焦)设置为白色。我尝试了以下代码。

  <android.support.design.widget.TextInputLayout
 android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:theme="@style/TextLabel">

<android.support.v7.widget.AppCompatEditText
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:hint="Hiiiii"
android:id="@+id/edit_id">
 </android.support.v7.widget.AppCompatEditText>
</android.support.design.widget.TextInputLayout>

<style name="TextLabel" parent="TextAppearance.AppCompat">
//hint color And Label Color in False State
<item name="android:textColorHint">@color/Color Name</item> 
<item name="android:textSize">20sp</item>
//Label color in True State And Bar Color False And True State
<item name="colorAccent">@color/Color Name</item>
<item name="colorControlNormal">@color/Color Name</item>
<item name="colorControlActivated">@color/Color Name</item>
</style>

在棒棒糖版本上它可以正常工作,但在更低的版本上却不行。我该如何在更低的版本上实现相同的效果?

2个回答

0

给予Text Input StyleEdittext相同的样式

 <!--Text Input Style-->
    <style name="styleTextInputLayout" parent="Widget.Design.TextInputLayout">
        <item name="android:textColor">?android:attr/textColorSecondary</item>
        <item name="android:textColorHint">?android:attr/textColorSecondaryInverse</item>
    </style>


 <!--EditText-->
    <style name="styleEditText" parent="Widget.AppCompat.EditText">
        <item name="android:textColor">?android:attr/textColorSecondary</item>
        <item name="android:textColorHint">?android:attr/textColorSecondaryInverse</item>
    </style>

给上面的标签分配相应的颜色

<android.support.design.widget.TextInputLayout
                    style="@style/styleTextInputLayout"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content">

                    <EditText
                        android:id="@+id/edtTextFirstName"
                        style="@style/styleEditText"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="@dimen/dimen_5_dp"
                        android:layout_marginTop="@dimen/dimen_5_dp"
                        android:hint="@string/hint_first_name"
                        android:imeOptions="actionNext"
                        android:inputType="textPersonName|textCapWords"
                        android:singleLine="true" />
                </android.support.design.widget.TextInputLayout>

上述代码适用于

compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'

我遇到了关于版本22的问题,可能是由于某些错误导致文本输入忽略了提供给它的样式。

com.android.support:design版本低于23的解决方案如下:

style.xml

 <style name="styleTextInputTextAppearance" parent="TextAppearance.AppCompat">
        <item name="android:textColorHint">?android:attr/textColorSecondaryInverse</item>
    </style>

将主题设置为TextInputLayout

<android.support.design.widget.TextInputLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:theme="@style/styleTextInputTextAppearance">

                    <EditText
                        android:id="@+id/edtTextTowerName"
                        style="@style/styleEditText"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="@dimen/dimen_5_dp"
                        android:layout_marginTop="@dimen/dimen_5_dp"
                        android:hint="@string/hint_tower_name"
                        android:imeOptions="actionNext"
                        android:inputType="textCapWords"
                        android:singleLine="true" />
                </android.support.design.widget.TextInputLayout>

0
我已经得到了答案。在低于棒棒糖版本的操作系统中,我们必须在应用程序主题中将文本颜色设置为白色(在我的情况下)。然后它就会起作用。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接