6

So I am trying to change the color of the background of the label on the TextInputLayout/EditText. Most other questions seem to be referring to the color of the text but the default functionality of the label I have observed is that the background of the label on the "OutlinedBox" style is it matches the background color of the layout above it in the hierarchy:

enter image description here

enter image description here

As you can see, in ex. 1, the layout above the TextInputLayout is a grayish color, so the Label TextView background also becomes grayish.

In Ex. 2, The layout above the TextInputLayout is a white color, so the Label Text background also becomes white. Since this is changing without any input from me (it's not using a color like "colorAccent" which it applies across the board, but instead is using a different color based on the layout background color).

What I am trying to find out is, Is there a color attribute I can maintain/edit, preferably via style, that will allow me to choose that color instead of defaulting it to whatever the layout above it in the hierarchy has?

I have tried setting various colors in Style to attempt to override the default behavior but have not found one that does so.

Here is a TextInputLayout/EditText for amount.

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/tilAmount"
    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
    android:layout_width="0dp"
    android:layout_height="55dp"
    android:layout_marginRight="@dimen/margin_between_boxes"
    android:layout_weight="1"
    android:hint="@string/et_amount"
    app:boxBackgroundColor="@color/white"
    app:boxStrokeColor="@color/editText_background"
    app:boxStrokeWidth="3dp"
    app:hintTextAppearance="@style/TextLabel">


        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/etAmount"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fontFamily="@font/neue_haas_grotesk_display_regular"
            android:inputType="number"
            android:maxLength="7"
            android:paddingLeft="13dp"
            android:textAlignment="viewStart"
            android:textColorHint="@android:color/black"
            android:textSize="14sp"
            android:layout_gravity="start" />
</com.google.android.material.textfield.TextInputLayout>

And here is the style used for hintTextAppearance

<style name="TextLabel" parent="TextAppearance.AppCompat">
    <!-- Hint color and label color in FALSE state -->
    <item name="android:textColorHint">@color/label_text</item>
    <item name="android:textColor">@color/label_text</item>
    <item name="android:textSize">12sp</item>
    <!-- Label color in TRUE state and bar color FALSE and TRUE State -->
    <item name="colorAccent">@android:color/black</item>
    <item name="colorControlNormal">@color/label_text</item>
    <item name="colorControlActivated">@color/label_text</item>
    <item name="android:colorControlHighlight">@color/label_text</item>
    <item name="android:textColorPrimary">@color/label_text</item>
    <item name="android:textColorSecondary">@color/label_text</item>
</style>

I expect to be able to edit the color of the background of the label TextView to whatever I choose.

Zain
  • 37,492
  • 7
  • 60
  • 84

0 Answers0