androidmaterial-designandroid-themeandroid-stylesautocompletetextview

Using android:autoCompleteTextViewStyle in theme.xml


So I have the following app theme:

<!-- 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>

And my example fragment layout looks like this:

<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>

What I want basically is to set the textsize of every appearing AutoCompleteTextView to lets say 14sp and the TextInputLayout should be outlined.

The issue is that the style item android:autoCompleteTextViewStyle doesn't affect any AutoCompleteTextView whatsoever. However, the funny thing is that the style item textInputStyle work's like a charm, as the default TextInputLayout would appear in outlined form without defining the style in the fragment layout file.

So my question ist:

Could it be that the style item: android:autoCompleteTextViewStyle is deprecated or that the style of the AutoCompleteTextView must be defined directly inside the layout file?


Solution

  • If u want to change the text size, text color or whatsoever, overriding the theme for the TextInputLayout is the way to go.

    Example:

    <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>