На TextInputLayout в Android всегда есть фон по умолчанию

У меня есть TextInputLayout и TextInputEditText такие

<com.google.android.material.textfield.TextInputLayout
            android:id = "@+id/loginUsernameText"
            android:layout_width = "match_parent"
            android:layout_height = "wrap_content"
            android:layout_marginLeft = "@dimen/text_input_margin_left_right"
            android:layout_marginRight = "@dimen/text_input_margin_left_right"
            android:layout_marginTop = "@dimen/text_input_margin_top_bottom"
            android:hint = "@string/username"
            android:layout_below = "@id/loginButtonLogin">

        <com.google.android.material.textfield.TextInputEditText
                android:id = "@+id/loginUsername"
                android:layout_width = "match_parent"
                android:padding = "5dp"
                android:layout_height = "wrap_content"
                android:inputType = "textEmailAddress"/>

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

    <com.google.android.material.textfield.TextInputLayout
            android:id = "@+id/loginPasswordText"
            android:layout_width = "match_parent"
            android:layout_height = "wrap_content"
            android:layout_marginLeft = "@dimen/text_input_margin_left_right"
            android:layout_marginRight = "@dimen/text_input_margin_left_right"
            android:layout_marginTop = "@dimen/text_input_margin_top_bottom"
            android:hint = "@string/password"
            android:layout_below = "@id/loginUsernameText">

        <com.google.android.material.textfield.TextInputEditText
                android:id = "@+id/loginPassword"
                android:layout_width = "match_parent"
                android:padding = "5dp"
                android:layout_height = "wrap_content"
                android:inputType = "textPassword"/>

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

Это мой файл styles.xml

<resources>

    <!-- Base application theme. -->
    <style name = "AppTheme" parent = "Theme.MaterialComponents.Light.NoActionBar">
        <!-- 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 = "AppTheme.NoActionBar">
        <item name = "windowActionBar">false</item>
        <item name = "windowNoTitle">true</item>
    </style>

    <style name = "AppTheme.AppBarOverlay" parent = "ThemeOverlay.AppCompat.Dark.ActionBar" />
    <style name = "AppTheme.PopupOverlay" parent = "ThemeOverlay.AppCompat.Light" />

    <style name = "TextAppearance.App.TextInputLayout" parent = "@android:style/TextAppearance">
        <item name = "android:textColor">@color/white</item>
        <item name = "android:textSize">14sp</item>
    </style>

</resources>

Поэтому я не использую ничего лишнего в TextInputLayout, и они выглядят так: На TextInputLayout в Android всегда есть фон по умолчанию

Этот серый фон есть всегда. Как удалить этот фон и просто получить TextInputLayout по умолчанию. Спасибо.

проверьте этот github.com/material-components/material-components-android/…

ॐ Rakesh Kumar 15.05.2019 06:10
26
1
26 283
9
Перейти к ответу Данный вопрос помечен как решенный

Ответы 9

Ответ принят как подходящий

https://github.com/material-components/material-components-android/issues/102

Кажется, существенная ошибка текстового поля.
Вы можете использовать этот код для временного изменения белого фона.

<com.google.android.material.textfield.TextInputLayout
   app:boxBackgroundColor = "@android:color/transparent" 
   android:background = "@android:color/transparent">
   <com.google.android.material.textfield.TextInputEditText/>
</com.google.android.material.textfield.TextInputLayout>

Один из способов удалить цвет фона — настроить фоновый режим TextInputLayout.

приложение: boxBackgroundMode = "нет"

Работал на меня.

Пример XML-кода:

<com.google.android.material.textfield.TextInputLayout
            android:layout_width = "match_parent"
            android:layout_height = "wrap_content"
            app:boxBackgroundMode = "none"
            app:errorEnabled = "true"
            app:hintEnabled = "false"
            app:layout_constraintTop_toTopOf = "parent">

            <com.google.android.material.textfield.TextInputEditText
                android:layout_width = "match_parent"
                android:layout_height = "wrap_content"
                android:gravity = "top"
                android:hint = "@string/comment_placeholder"
                android:inputType = "textCapSentences|textMultiLine"
                android:maxLength = "500" />

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

Наслаждайтесь репутацией! Ха-ха! Спасибо за ответ!

OhhhThatVarun 14.09.2019 22:29

После того, как я обновил материальный дизайн в своем проекте, я заметил, что макеты ввода текста с boxBackgroundMode, для которого установлено значение none, отображают значок ошибки. Не уверен, что это ошибка, но я установил прозрачный цвет значка ошибки, чтобы решить эту проблему на данный момент. - "приложение:errorIconTint = "@android:color/transparent"

Andrew 28.09.2019 22:27

Он также удаляет подчеркивание

gbixahue 23.06.2020 14:10

Мой TextInputLayout оборачивает AutoCompleteTextView для реализации спиннера материала. Мне также пришлось установить app:endIconMode = "none", потому что стиль материала по умолчанию применяет стрелку раскрывающегося списка к TIL в качестве значка конца. Если не установлено, выдается исключение: The current box background mode 0 is not supported by the end icon mode 3. Но как только я это сделаю, выпадающий список больше не работает!

rmirabelle 04.02.2021 20:06

Для меня это сработало с app:boxBackgroundColor = "@null", вот так:

    <com.google.android.material.textfield.TextInputLayout
        android:layout_width = "match_parent"
        android:layout_height = "wrap_content"
        app:boxBackgroundColor = "@null"
        android:hint = "@string/description">

        <com.google.android.material.textfield.TextInputEditText
            android:id = "@+id/description"
            android:layout_width = "match_parent"
            android:layout_height = "wrap_content"
            android:inputType = "textMultiLine|textCapSentences" />

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

В моем случае необходимо изменить фон в TextInputLayout и TextInputEditText

<com.google.android.material.textfield.TextInputLayout
    app:boxBackgroundColor = "@color/transparent"
    android:background = "@color/transparent"
    >
    <com.google.android.material.textfield.TextInputEditText
        android:background = "@color/transparent"
        />
</com.google.android.material.textfield.TextInputLayout>

Я недавно столкнулся с этой проблемой. Ни одно из вышеперечисленных решений не работало для последней версии материальной темы. Мне потребовалось время, чтобы понять это. Вот мое решение:

Стиль:

<style name = "Widget.App.TextInputLayout" parent = "Widget.Design.TextInputLayout">
    <item name = "materialThemeOverlay">@style/ThemeOverlay.App.TextInputLayout</item>
    <item name = "hintTextColor">@color/pink</item>
    <item name = "android:textColorHint">@color/grey</item>
</style>

<style name = "ThemeOverlay.App.TextInputLayout" parent = "">
    <item name = "colorControlNormal">@color/grey</item>
</style>

Применение:

<com.google.android.material.textfield.TextInputLayout
        android:id = "@+id/password"
        style = "@style/Widget.App.TextInputLayout"
        android:layout_width = "0dp"
        android:layout_height = "wrap_content"
        android:hint = "@string/password"
        app:layout_constraintBottom_toTopOf = "@+id/agreement"
        app:layout_constraintEnd_toEndOf = "parent"
        app:layout_constraintStart_toStartOf = "parent"
        app:layout_constraintTop_toBottomOf = "@+id/email">

        <com.google.android.material.textfield.TextInputEditText
            android:layout_width = "match_parent"
            android:layout_height = "wrap_content"
            android:inputType = "textPassword"/>

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

Also I strongly recommend you to check this article out. Migrating to Material Components for Android

Цвет фона по умолчанию основан на атрибуте colorOnSurface.

Вы можете переопределить это значение, используя:

<com.google.android.material.textfield.TextInputLayout
   android:theme = "@style/MyTextInputLayout_overlay"
   ..>

с участием:

<style name = "MyTextInputLayout_overlay">
    <item name = "colorOnSurface">@color/....</item>
</style>

или вы можете использовать атрибут boxBackgroundColor (в макете или в пользовательском стиле):

  <com.google.android.material.textfield.TextInputLayout
      app:boxBackgroundColor = "@color/....."
      ..>

Приложение <com.google.android.material.textfield.TextInputLayout:boxBackgroundColor = "@color/....." ..> сработало для меня. Спасибо

Ajay 11.11.2021 21:20

Простой способ сработал для меня!

app:boxBackgroundMode = "filled"
app:boxBackgroundColor = "@color/white"

Спас мой день, спасибо :)

Jona 21.09.2021 10:28

Метод А

(полностью прозрачный фон)

<com.google.android.material.textfield.TextInputLayout
    app:boxBackgroundMode = "filled"
    app:boxBackgroundColor = "@null"
..>

<com.google.android.material.textfield.TextInputEditText
    android:backgroundTint = "@android:color/transparent"
..>

Метод Б

(сплошной цвет фона)

<com.google.android.material.textfield.TextInputLayout
    app:boxBackgroundMode = "filled"
    app:boxBackgroundColor = "?android:attr/colorBackground"
..>

* В моем случае мне нужно было, чтобы он был полностью прозрачным, так как фон экрана не является сплошным цветом. Если это ваш случай, используйте Метод А.

В начале все работало нормально. Позднее макет был нарушен. Причина в том, что я изменил фон свойства TextInputEditText. Прозрачность должна быть установлена ​​в TextInputEditText, а не в TextInputLayout android:background = "#80FFFFFF"

Другие вопросы по теме