Как я могу изменить цвет фона текста подсказки TextInputLayout - PullRequest
0 голосов
/ 15 марта 2020

Я программирую представление TextInputLayout

Мой стиль. xml:

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="MyTextInputLayoutStyle" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
    <item name="boxStrokeColor">@color/colorPrimary</item>
    <item name="hintTextColor">@color/colorPrimary</item>
    <item name="boxBackgroundColor">@android:color/white</item>
    <item name="boxStrokeWidth">2dp</item>
</style>

Мои переопределения цвета в цвете. xml:

<color name="mtrl_textinput_default_box_stroke_color" tools:override="true">#c2261a</color>

Мой макет TextImput:

<com.google.android.material.textfield.TextInputLayout
        android:id="@+id/weightInput"
        style="@style/MyTextInputLayoutStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:layout_marginBottom="15dp"
        android:hint="@string/hint_weight"
        app:errorEnabled="true"
        app:helperTextEnabled="false"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textViewTitle">

        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:imeOptions="actionDone"
            android:importantForAutofill="no"
            android:inputType="numberDecimal"
            android:maxLength="5"
            android:maxLines="1"
            android:singleLine="true"
            android:textAlignment="center"
            android:textColor="@color/colorPrimary" />

    </com.google.android.material.textfield.TextInputLayout>

И конечный результат

final result

As мы видим, что цвет фона текста подсказки прозрачен. Пожалуйста, научите меня, как найти это представление.

Я попробовал этот стиль без успеха:

Мой стиль. xml это:

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="HintText" parent="TextAppearance.Design.Hint">
    <item name="android:textColor">@color/colorPrimary</item>
    <item name="android:background">@android:color/white</item>
</style>

<style name="MyTextInputLayoutStyle" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
    <item name="boxStrokeColor">@color/colorPrimary</item>
    <item name="hintTextColor">@color/colorPrimary</item>
    <item name="hintTextAppearance">@style/HintText</item>
    <item name="boxBackgroundColor">@android:color/white</item>
    <item name="boxStrokeWidth">2dp</item>
</style>

Спасибо и счастливого дня!

PS: Я не проверял свои опечатки в испанском sh.

1 Ответ

0 голосов
/ 15 марта 2020

использовать backgroundTint в TextInputEditText

android:backgroundTint="@color/colorPrimaryDark"

пример кода:

<com.google.android.material.textfield.TextInputEditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:backgroundTint="@color/colorPrimaryDark"
                    android:imeOptions="actionNext"
                    tools:text="Full name" />
...