Material 设计 TextInput 更改标签和助手大小
Material Design TextInput change label and helper size
在 Material 设计 TextInput 中,如何更改带有样式的标签和助手的大小 XML。
我遵循了 Material 设计 codelab,代码实验室显示的标签至少是我的标签的 3 倍。
我的标签不可读。
Codelabs 标签
不确定,但这是我的 XML 代码
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/new_first_name"
style="@style/TestInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="First Name"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
/>
</com.google.android.material.textfield.TextInputLayout>
我的风格XML
<style name="TestInput" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
<item name="hintTextAppearance">@color/black</item>
<item name="hintTextColor">@color/black</item>
<item name="android:paddingBottom">16dp</item>
<item name="boxStrokeColor">@color/colorAccent</item>
<item name="maxLines">1</item>
<item name="helperText">@string/first_name</item>
<item name="android:colorControlHighlight">@color/orange</item>
<item name="counterMaxLength">20</item>
<item name="endIconMode">clear_text</item>
<item name="android:layout_marginTop">16dp</item>
<item name="android:layout_marginStart">16dp</item>
<item name="android:layout_marginEnd">16dp</item>
</style>
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintTextAppearance="@style/TextAppearance.AppCompat.Medium.Inverse">
app:hintTextAppearance="@style/TextAppearance.AppCompat.Medium.Inverse 使用。
其他解决方案
<style name="CustomTextAppearance" parent="@android:style/TextAppearance">
<item name="android:textSize">16sp</item>
<item name="android:textColor">@color/colorAccent</item>
</style>
app:hintTextAppearance="@style/CustomTextAppearance"
您可以在布局或自定义样式中使用 hintTextAppearance
和 helperTextTextAppearance
属性。
类似于:
<com.google.android.material.textfield.TextInputLayout
app:hintTextAppearance="@style/App.hintTextAppearance"
app:helperTextTextAppearance="@style/App.helperTextTextAppearance"
...>
与:
<style name="App.hintTextAppearance" parent="TextAppearance.MaterialComponents.Caption">
<item name="android:textSize">xxsp</item>
</style>
<style name="App.helperTextTextAppearance" parent="TextAppearance.MaterialComponents.Caption">
<item name="android:textSize">xxsp</item>
</style>
在 Material 设计 TextInput 中,如何更改带有样式的标签和助手的大小 XML。
我遵循了 Material 设计 codelab,代码实验室显示的标签至少是我的标签的 3 倍。
我的标签不可读。
Codelabs 标签
不确定,但这是我的 XML 代码
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/new_first_name"
style="@style/TestInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="First Name"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
/>
</com.google.android.material.textfield.TextInputLayout>
我的风格XML
<style name="TestInput" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
<item name="hintTextAppearance">@color/black</item>
<item name="hintTextColor">@color/black</item>
<item name="android:paddingBottom">16dp</item>
<item name="boxStrokeColor">@color/colorAccent</item>
<item name="maxLines">1</item>
<item name="helperText">@string/first_name</item>
<item name="android:colorControlHighlight">@color/orange</item>
<item name="counterMaxLength">20</item>
<item name="endIconMode">clear_text</item>
<item name="android:layout_marginTop">16dp</item>
<item name="android:layout_marginStart">16dp</item>
<item name="android:layout_marginEnd">16dp</item>
</style>
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintTextAppearance="@style/TextAppearance.AppCompat.Medium.Inverse">
app:hintTextAppearance="@style/TextAppearance.AppCompat.Medium.Inverse 使用。
其他解决方案
<style name="CustomTextAppearance" parent="@android:style/TextAppearance">
<item name="android:textSize">16sp</item>
<item name="android:textColor">@color/colorAccent</item>
</style>
app:hintTextAppearance="@style/CustomTextAppearance"
您可以在布局或自定义样式中使用 hintTextAppearance
和 helperTextTextAppearance
属性。
类似于:
<com.google.android.material.textfield.TextInputLayout
app:hintTextAppearance="@style/App.hintTextAppearance"
app:helperTextTextAppearance="@style/App.helperTextTextAppearance"
...>
与:
<style name="App.hintTextAppearance" parent="TextAppearance.MaterialComponents.Caption">
<item name="android:textSize">xxsp</item>
</style>
<style name="App.helperTextTextAppearance" parent="TextAppearance.MaterialComponents.Caption">
<item name="android:textSize">xxsp</item>
</style>