![](/img/trans.png)
[英]Error message spacing not working in TextInputLayout Outlined style
[英]Global style for TextInputLayout is not working
我想將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>
但它永遠不會奏效。 對上述問題解決方案的任何建議表示高度贊賞。
您必須將這些屬性應用於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" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.