Не могу заставить работать OutlinedBox для TextInputEditText. На Stackoverflow есть похожий вопрос, но ни одно из решений не работает.
Как только я добавляю android:style = "@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" в код, форма исчезает из предварительного просмотра, и когда я пытаюсь создать apk, появляется эта ошибка:
Android resource linking failed
com.my.app-main-50:/layout/fragment_login.xml:32: error: attribute android:style not found.
error: failed linking file resources.
Ставлю просто style = "@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
Тоже не работает
Скриншот
Построить.градле:
implementation 'com.google.android.material:material:1.7.0'
Код:
<RelativeLayout
xmlns:android = "http://schemas.android.com/apk/res/android"
xmlns:tools = "http://schemas.android.com/tools"
xmlns:app = "http://schemas.android.com/apk/res-auto"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
android:paddingBottom = "@dimen/activity_vertical_margin"
android:paddingLeft = "@dimen/activity_horizontal_margin"
android:paddingRight = "@dimen/activity_horizontal_margin"
android:paddingTop = "@dimen/activity_vertical_margin"
android:background = "#EAEAEA"
tools:context = ".LoginFragment">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width = "match_parent"
android:layout_height = "80dp"
android:src = "@drawable/logo_src"
android:layout_alignParentStart = "true"
android:id = "@+id/imageLogo"
android:layout_alignParentTop = "true"
android:contentDescription = "@string/t_logo"/>
<TextView
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:textAppearance = "?android:attr/textAppearanceLarge"
android:text = "@string/app_description"
android:id = "@+id/appTitle"
android:layout_below = "@+id/imageLogo"
android:layout_marginBottom = "8dp"
android:layout_centerHorizontal = "true" />
<com.google.android.material.textfield.TextInputLayout
android:id = "@+id/editLoginWrapper"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_below = "@+id/appTitle"
android:hint = "@string/login_hint"
android:layout_marginTop = "8dp"
android:layout_marginBottom = "8dp">
<com.google.android.material.textfield.TextInputEditText
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:style = "@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:id = "@+id/editLogin"
android:inputType = "text" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id = "@+id/editPasswordWrapper"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_below = "@+id/editLoginWrapper"
android:layout_marginTop = "8dp"
android:layout_marginBottom = "8dp"
android:hint = "@string/password_hint"
app:endIconMode = "password_toggle">
<com.google.android.material.textfield.TextInputEditText
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:inputType = "textPassword"
android:id = "@+id/editPassword" />
</com.google.android.material.textfield.TextInputLayout>
<androidx.appcompat.widget.AppCompatButton
android:id = "@+id/signIn"
style = "?attr/buttonStyle"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:text = "@string/sign_in"
android:layout_below = "@+id/editPasswordWrapper"
android:textSize = "@dimen/button_text"
android:textColor = "@color/white"
android:enabled = "true"
android:layout_centerHorizontal = "true"
app:backgroundTint = "@color/button_background" />
<Button
android:id = "@+id/forgotPassword"
style = "?attr/buttonBarButtonStyle"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_below = "@+id/signIn"
android:layout_centerHorizontal = "true"
android:text = "@string/forgot_password"
android:textColor = "#918B8B"
android:textColorHighlight = "#DC6C6C"
android:textColorLink = "#5E5E5E" />
</RelativeLayout>
Стиль внутри TextInputLayout:
<com.google.android.material.textfield.TextInputLayout
android:id = "@+id/editLoginWrapper"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_below = "@+id/appTitle"
android:hint = "@string/login_hint"
android:layout_marginTop = "8dp"
style = "@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_marginBottom = "8dp">
Приложение просто вылетает:
FATAL EXCEPTION: main
android.view.InflateException: Binary XML file line #41 in com.app.app:layout/fragment_login: Binary XML file line #41 in com.app.app:layout/fragment_login: Error inflating class com.google.android.material.textfield.TextInputLayout
Caused by: android.view.InflateException: Binary XML file line #41 in com.app.app:layout/fragment_login: Error inflating class com.google.android.material.textfield.TextInputLayout
Строка 41:
style = "@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
Я пробовал все это. Я только что обновил свой вопрос.
Добавьте стиль в TextInputLayout не TextInputEditText
style = "@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
И добавьте тему в корневой макет, и ваша тема активности должна быть MaterialComponents
android:theme = "@style/Theme.MaterialComponents.Light"
Вы пробовали Invalidate и Restart и перестраивать проект? Кроме того, стиль, который вы устанавливаете для TextInputEditText, фактически предназначен для TextInputLayout. Попробуйте установить его в TextInputLayout.