#android #material-design #material-components-android #android-textinputlayout
#Android #материал-дизайн #материал-компоненты-android #android-textinputlayout
Вопрос:
Я хочу установить пользовательский стиль на TextInputLayout
глобальном уровне как:
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.BudgetTracker" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
...
<!-- Secondary brand color. -->
...
<!-- Status bar color. -->
...
<!-- Customize your theme here. -->
<item name="fontFamily">@font/regular</item>
<!-- TextInputLayout-->
<item name="textInputStyle">@style/Widget.MyNiceAppName.TextInputLayout.OutlinedBox</item>
</style>
<style name="Widget.MyNiceAppName.TextInputLayout.OutlinedBox" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="android:imeOptions">actionNext</item>
<item name="android:maxLines">1</item>
</style>
</resources>
и мой макет фрагмента
<com.google.android.material.textfield.TextInputLayout
android:id="@ id/outlinedTextField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="32dp"
android:hint="@string/label_email"
android:inputType="textEmailAddress"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@ id/acll">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
но это никогда не работает. Любые предложения по упомянутому решению проблемы высоко ценятся.
Комментарии:
1. Я попробовал тот же код в своем приложении, он сработал. Это «maxlines», которые, похоже, не работают для вас?
2. Спасибо, но на моей стороне
android:imeOptions
иandroid:maxLines
оба не работают.
Ответ №1:
Вы должны применить эти атрибуты TextInputEditText
не к TextInputLayout
.
В вашем случае вы можете использовать:
<style name="Widget.MyNiceAppName.TextInputLayout.OutlinedBox" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="materialThemeOverlay">
@style/ThemeOverlay.App.TextInputEditText.OutlinedBox
</item>
</style>
<style name="ThemeOverlay.App.TextInputEditText.OutlinedBox" parent="ThemeOverlay.MaterialComponents.TextInputEditText.OutlinedBox">
<item name="editTextStyle">@style/Widget.App.TextInputEditText.OutlinedBox</item>
</style>
<style name="Widget.App.TextInputEditText.OutlinedBox" parent="Widget.MaterialComponents.TextInputEditText.OutlinedBox">
<item name="android:imeOptions">actionNext</item>
<item name="android:maxLines">1</item>
</style>
Также вы можете добавить android:inputType="textEmailAddress"
в TextInputEditText
:
<com.google.android.material.textfield.TextInputEditText
android:inputType="textEmailAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content" />