所以我有以下应用程序主题:
<!-- Base application theme. -->
<style name="Theme.Base.App" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/DeepSkyBlue</item>
<item name="colorPrimaryVariant">@color/DeepSkyBlueVariant</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/white</item>
<!-- Background color of the entire window/screen-->
<item name="android:windowBackground">@color/GhostWhite</item>
<!-- This defines the default style for the text-input layouts: outlined
In case there is mixture of text-input layouts
e.g. exposed dropdown and outlined, then the exposed dropdown style must be defined in the according layout file
-->
<item name="textInputStyle">
@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox
</item>
<!-- This doesn't work. Neighter the textSize nor the textColor get changed....
-->
<item name="android:autoCompleteTextViewStyle">
@style/AutoCompleteTextViewMediumStyle
</item>
</style>
<style name="AutoCompleteTextViewMediumStyle" parent="Widget.AppCompat.AutoCompleteTextView">
<item name="android:textSize">@dimen/text_medium</item>
<item name="android:textColor">@color/design_default_color_error</item>
</style>
和我的例子片段布局看起来像这样:
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/layout_margin_default"
android:hint="@string/vehicle_type"
android:labelFor="@id/autocomplete_textview_vehicle_type"
app:startIconDrawable="@drawable/baseline_commute_24">
<AutoCompleteTextView
android:id="@+id/autocomplete_textview_vehicle_type"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="none" />
</com.google.android.material.textfield.TextInputLayout>
我想要的基本上是设置每个出现的AutoCompleteTextView
的文本大小为14sp,TextInputLayout
应该被概述。
问题是样式项android:autoCompleteTextViewStyle
不会影响任何AutoCompleteTextView
。然而,有趣的是,样式项textInputStyle
的工作就像一个魅力,因为默认的TextInputLayout
将以轮廓形式出现,而无需在片段布局文件中定义样式。
所以我的问题列表:
可能是样式项:android:autoCompleteTextViewStyle
被弃用,或者AutoCompleteTextView
的样式必须直接在布局文件中定义?
如果你想改变文字的大小,文字的颜色或任何东西,覆盖TextInputLayout
的主题是一种方式。
的例子:
<item name="textInputStyle">
@style/TextInputThemeStyle
</item>
<style name="TextInputThemeStyle" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="materialThemeOverlay">@style/ThemeOverlay.Material3.TextInputEditText.OutlinedBox.ThemeStyle</item>
</style>
<style name="ThemeOverlay.Material3.TextInputEditText.OutlinedBox.ThemeStyle" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="android:textSize">your text size.</item>
<item name="android:textColor">your text color</item>
</style>