【问题标题】:Using android:autoCompleteTextViewStyle in theme.xml在 theme.xml 中使用 android:autoCompleteTextViewStyle
【发布时间】:2022-12-10 19:04:32
【问题描述】:

所以我有以下应用程序主题:

<!-- 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 的样式必须直接在布局文件中定义?

【问题讨论】:

    标签: android material-design android-theme android-styles autocompletetextview


    【解决方案1】:

    如果您想更改文本大小、文本颜色或其他任何内容,覆盖 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-11
      • 2021-06-30
      • 2013-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多