在我的应用程序中,我使用Theme.MaterialComponents.Light.NoActionBar
作为基本样式。这种风格,我称之为AppTheme
,我正在尝试覆盖editTextStyle
提供自定义样式com.google.android.material.textfield.TextInputEditText
(根据源代码,它使用R.attr.editTextStyle
作为默认样式)。
这是我当前的主题,与 TIEditText 和 TILayout 相关:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
[ primary and secondary colors, OnColors, etc.]
<item name="editTextStyle">@style/AppTheme.TextInputEditText</item>
<item name="textInputStyle">@style/AppTheme.TextInputLayout</item>
[ Custom attribute for testing, defined in attrs.xml ]
<item name="textInputEditTextStyle">@style/AppTheme.TextInputEditText</item>
</style>
由于某种原因,即使我设置editTextStyle
,如果我在代码中使用它,它不会被应用:
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tilFirstName"
style="?attr/textInputStyle"
android:hint="@string/label_firstname"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/firstName"
style="?attr/editTextStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text="@={viewModel.firstName}" />
</com.google.android.material.textfield.TextInputLayout>
但是如果我更换样式firstName
with ?attr/textInputEditTextStyle
, 有用。
为什么我不能覆盖editTextStyle
在默认主题中?这到底是怎么回事?
Target SDK 为 28,minSDK 为 21,Material 库版本为1.1.0-alpha06