将 Material 1.1.0 的版本更改为 1.3.0
Change Version Of Material 1.1.0 to 1.3.0
我的第二个问题:
我使用 TextInputLayout :
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColorHint="@color/LightBlue"
android:theme="@style/ThemeOverlay.AppTheme.TextInputEditText.Outlined"
app:boxStrokeColor="@color/selector"
app:boxStrokeWidth="3dp"
app:startIconTint="@color/white">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/numberOfPlayer_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:inputType="numberDecimal"
android:textColor="@color/gold" />
</com.google.android.material.textfield.TextInputLayout>
样式文件
<style name="AppTheme"
parent="Theme.MaterialComponents.Light.NoActionBar.Bridge">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowBackground">@color/Thistle</item>
<!-- use in get player information -->
<item name="CustomTextStyle">@style/Widget.App. TextInputLayout.
OutlinedBox</item>
</style>
<style name="ThemeOverlay.AppTheme.TextInputEditText.Outlined"
parent="">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="boxCornerRadiusBottomEnd">20dp</item>
<item name="boxCornerRadiusBottomStart">20dp</item>
<item name="boxCornerRadiusTopEnd">20dp</item>
<item name="boxCornerRadiusTopStart">20dp</item>
<item name="android:hint">Number of player</item>
<item name="hintTextColor">@color/card1</item>
<item name="startIconDrawable">@drawable/ic_people</item>
</style>
<style name="Widget.App.TextInputLayout.OutlinedBox"
parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="boxStrokeColor">@color/player_information</item>
<item name="boxCornerRadiusBottomEnd">15dp</item>
<item name="boxCornerRadiusBottomStart">15dp</item>
<item name="boxCornerRadiusTopEnd">15dp</item>
<item name="boxCornerRadiusTopStart">15dp</item>
<item name="android:textColorHint">@color/white</item>
<item name="startIconDrawable">@drawable/player</item>
<item name="startIconTint">@color/gold</item>
<item name="elevation">5dp</item>
<item name="boxStrokeWidth">2dp</item>
<itemname="materialThemeOverlay">@style/ThemeOverlay.App.
TextInputEditText.OutlinedBox</item>
<item name="hintTextColor">@color/AntiqueWhite</item>
<!-- .... -->
</style>
<style name="ThemeOverlay.App.TextInputEditText.OutlinedBox"
parent="ThemeOverlay.MaterialComponents.TextInputEditText.OutlinedBox">
<!-- to change the cursor color -->
<item name="colorControlActivated">@color/white</item>
</style>
这是我的选择器文件
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/DarkSeaGreen"
android:state_focused="true"/>
<item android:color="@color/white"/>
</selector>
和属性
<resources>
<attr name="customTextInputStyle" format="reference" />
<attr name="CustomTextStyle" formet ="reference"/>
</resources>
当我将 material 1.1.0 的版本更改为 1.3.0 时,我之前创建的文本输入布局 1 的形状变形了。它变得比以前更宽了。我找不到这个的原因 change.As 你可以在图片中看到,文本输入布局很宽,提示文本在背面看起来仍然是黑色的。
main 问题在 ThemeOverlay 中。您必须添加父 ThemeOverlay.MaterialComponents.TextInputEditText.OutlinedBox
.
<style name="ThemeOverlay.App.TextInputEditText.OutlinedBox" parent="@style/ThemeOverlay.MaterialComponents.TextInputEditText.OutlinedBox">
<item name="colorPrimary">@color/...</item>
</style>
需要,因为您要扩展的默认样式 Widget.MaterialComponents.TextInputLayout.OutlinedBox
定义了自己的 materialThemeOverlay
和
没有父依赖项,您将失去默认行为。
也在您的 xml 布局中 删除 android:theme="@style/ThemeOverlay.AppTheme.TextInputEditText.Outlined"
。您不需要它,因为您已经在样式中使用 materialThemeOverlay
,并且 xml 布局中定义的主题覆盖了它,并且此主题覆盖是错误的。
还有:
- 使用最小宽度,因为您使用的是大角半径
15dp
<com.google.android.material.textfield.TextInputLayout
android:minWidth="150dp"
android:layout_width="wrap_content"
- 最终提示使用的颜色:
<item name="android:textColorHint">@color/red600Dark</item>
<item name="hintTextColor">@color/teal_700</item>
最终布局:
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.App.TextInputLayout.OutlinedBox"
android:minWidth="150dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:startIconTint="@color/white">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/numberOfPlayer_txt"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="numberDecimal"
android:textColor="@color/gold" />
</com.google.android.material.textfield.TextInputLayout>
与:
<style name="Widget.App.TextInputLayout.OutlinedBox"
parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="boxStrokeColor">@color/text_input_stroke_selector</item>
<item name="boxCornerRadiusBottomEnd">15dp</item>
<item name="boxCornerRadiusBottomStart">15dp</item>
<item name="boxCornerRadiusTopEnd">15dp</item>
<item name="boxCornerRadiusTopStart">15dp</item>
<item name="startIconDrawable">@drawable/ic_...</item>
<item name="startIconTint">@color/...</item>
<item name="elevation">5dp</item>
<item name="boxStrokeWidth">2dp</item>
<item name="materialThemeOverlay">@style/ThemeOverlay.App.TextInputEditText.OutlinedBox</item>
<item name="android:textColorHint">@color/....</item>
<item name="hintTextColor">@color/....</item>
</style>
<style name="ThemeOverlay.App.TextInputEditText.OutlinedBox" parent="@style/ThemeOverlay.MaterialComponents.TextInputEditText.OutlinedBox">
<item name="colorPrimary">@color/....</item>
</style>
我的第二个问题: 我使用 TextInputLayout :
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColorHint="@color/LightBlue"
android:theme="@style/ThemeOverlay.AppTheme.TextInputEditText.Outlined"
app:boxStrokeColor="@color/selector"
app:boxStrokeWidth="3dp"
app:startIconTint="@color/white">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/numberOfPlayer_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:inputType="numberDecimal"
android:textColor="@color/gold" />
</com.google.android.material.textfield.TextInputLayout>
样式文件
<style name="AppTheme"
parent="Theme.MaterialComponents.Light.NoActionBar.Bridge">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowBackground">@color/Thistle</item>
<!-- use in get player information -->
<item name="CustomTextStyle">@style/Widget.App. TextInputLayout.
OutlinedBox</item>
</style>
<style name="ThemeOverlay.AppTheme.TextInputEditText.Outlined"
parent="">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="boxCornerRadiusBottomEnd">20dp</item>
<item name="boxCornerRadiusBottomStart">20dp</item>
<item name="boxCornerRadiusTopEnd">20dp</item>
<item name="boxCornerRadiusTopStart">20dp</item>
<item name="android:hint">Number of player</item>
<item name="hintTextColor">@color/card1</item>
<item name="startIconDrawable">@drawable/ic_people</item>
</style>
<style name="Widget.App.TextInputLayout.OutlinedBox"
parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="boxStrokeColor">@color/player_information</item>
<item name="boxCornerRadiusBottomEnd">15dp</item>
<item name="boxCornerRadiusBottomStart">15dp</item>
<item name="boxCornerRadiusTopEnd">15dp</item>
<item name="boxCornerRadiusTopStart">15dp</item>
<item name="android:textColorHint">@color/white</item>
<item name="startIconDrawable">@drawable/player</item>
<item name="startIconTint">@color/gold</item>
<item name="elevation">5dp</item>
<item name="boxStrokeWidth">2dp</item>
<itemname="materialThemeOverlay">@style/ThemeOverlay.App.
TextInputEditText.OutlinedBox</item>
<item name="hintTextColor">@color/AntiqueWhite</item>
<!-- .... -->
</style>
<style name="ThemeOverlay.App.TextInputEditText.OutlinedBox"
parent="ThemeOverlay.MaterialComponents.TextInputEditText.OutlinedBox">
<!-- to change the cursor color -->
<item name="colorControlActivated">@color/white</item>
</style>
这是我的选择器文件
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/DarkSeaGreen"
android:state_focused="true"/>
<item android:color="@color/white"/>
</selector>
和属性
<resources>
<attr name="customTextInputStyle" format="reference" />
<attr name="CustomTextStyle" formet ="reference"/>
</resources>
当我将 material 1.1.0 的版本更改为 1.3.0 时,我之前创建的文本输入布局 1 的形状变形了。它变得比以前更宽了。我找不到这个的原因 change.As 你可以在图片中看到,文本输入布局很宽,提示文本在背面看起来仍然是黑色的。
main 问题在 ThemeOverlay 中。您必须添加父 ThemeOverlay.MaterialComponents.TextInputEditText.OutlinedBox
.
<style name="ThemeOverlay.App.TextInputEditText.OutlinedBox" parent="@style/ThemeOverlay.MaterialComponents.TextInputEditText.OutlinedBox">
<item name="colorPrimary">@color/...</item>
</style>
需要,因为您要扩展的默认样式 Widget.MaterialComponents.TextInputLayout.OutlinedBox
定义了自己的 materialThemeOverlay
和
没有父依赖项,您将失去默认行为。
也在您的 xml 布局中 删除 android:theme="@style/ThemeOverlay.AppTheme.TextInputEditText.Outlined"
。您不需要它,因为您已经在样式中使用 materialThemeOverlay
,并且 xml 布局中定义的主题覆盖了它,并且此主题覆盖是错误的。
还有:
- 使用最小宽度,因为您使用的是大角半径
15dp
<com.google.android.material.textfield.TextInputLayout
android:minWidth="150dp"
android:layout_width="wrap_content"
- 最终提示使用的颜色:
<item name="android:textColorHint">@color/red600Dark</item>
<item name="hintTextColor">@color/teal_700</item>
最终布局:
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.App.TextInputLayout.OutlinedBox"
android:minWidth="150dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:startIconTint="@color/white">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/numberOfPlayer_txt"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="numberDecimal"
android:textColor="@color/gold" />
</com.google.android.material.textfield.TextInputLayout>
与:
<style name="Widget.App.TextInputLayout.OutlinedBox"
parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="boxStrokeColor">@color/text_input_stroke_selector</item>
<item name="boxCornerRadiusBottomEnd">15dp</item>
<item name="boxCornerRadiusBottomStart">15dp</item>
<item name="boxCornerRadiusTopEnd">15dp</item>
<item name="boxCornerRadiusTopStart">15dp</item>
<item name="startIconDrawable">@drawable/ic_...</item>
<item name="startIconTint">@color/...</item>
<item name="elevation">5dp</item>
<item name="boxStrokeWidth">2dp</item>
<item name="materialThemeOverlay">@style/ThemeOverlay.App.TextInputEditText.OutlinedBox</item>
<item name="android:textColorHint">@color/....</item>
<item name="hintTextColor">@color/....</item>
</style>
<style name="ThemeOverlay.App.TextInputEditText.OutlinedBox" parent="@style/ThemeOverlay.MaterialComponents.TextInputEditText.OutlinedBox">
<item name="colorPrimary">@color/....</item>
</style>