4

I'm trying to style a TextInputLayout with OutlinedBox wrapping a TextInputEditText. I was already able to set border-box color and hint text color attributes, depending on the state, but I'm not able to apply a white background to the area within the box. A lot of questions are related to the hint text color and just a few reports this behavior, without a proper solution. This question report the same problem but, as pointed out in the answer, there seems to be no solution.

Anyway, as you can see here, by applying a background to the inner TextInputEditText the hint/label actually acts as intended, but the TextInputLayout loses the rounded border. So there must be a way to apply a "transparent" background to the hint, right?

Layout ( .... are just id and constraint attributes)

<androidx.constraintlayout.widget.ConstraintLayout
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="@color/colorPrimary"
  ....
    <com.google.android.material.textfield.TextInputLayout
       style="@style/LoginTextInputLayout"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        ... >
    <com.google.android.material.textfield.TextInputEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:textSize="18sp"/>
    </com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

Style (TextInputLayout styling is only made here right now)

<style name="LoginTextInputLayout" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
    <item name="android:textColorHint">@color/colorAccent</item>
    <item name="hintTextColor">@color/colorAccent</item>
    <item name="boxStrokeColor">@color/text_input_layout_login_selector</item>
    <item name="boxStrokeWidthFocused">1dp</item>
</style>

Is there any way to keep the "transparent background" for the floating hint label, the outline for the box and the background for the inner area?

Michael m
  • 354
  • 5
  • 15
  • https://stackoverflow.com/questions/60898946/materialcomponents-textinputlayout-outlinedbox-it-doesnt-work-properly-boxbackg/60910419#60910419 – MMG May 05 '20 at 16:29

0 Answers0