【问题标题】:Android SearchView Not Applying StyleAndroid SearchView 不应用样式
【发布时间】:2023-03-04 22:05:02
【问题描述】:

我添加到我的 Activity(不在工具栏中)的 android.support.v7.widget.SearchView 似乎没有完全应用我创建的样式。

这是 SearchView 本身的代码,我在其中引用 AppTheme.SearchView 作为它应该应用的样式。

<android.support.v7.widget.SearchView
                android:id="@+id/search_dashboard"
                style="@style/AppTheme.SearchView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/color_primary"
                android:layout_below="@id/toolbar_dashboard"
                android:elevation="@dimen/toolbar_elevation" />

这是样式的代码:

<style name="AppTheme.SearchView" parent="Widget.AppCompat.Light.SearchView">

    <item name="android:colorPrimary">@android:color/white</item>
    <item name="android:colorPrimaryDark">@android:color/white</item>
    <item name="android:textColorPrimary">@android:color/white</item>
    <item name="android:textColorSecondary">@android:color/white</item>
    <item name="android:textColor">@android:color/white</item>

    <!-- Gets rid of the search icon when the SearchView is expanded -->
    <item name="searchHintIcon">@null</item>
    <!-- The hint text that appears when the user has not typed anything -->
    <item name="queryHint">Test 1</item>
</style>

我正在尝试将图标的颜色和所有文本设置为白色。 当我执行应用程序时,我得到了这个结果:

您可以看到我应用了样式的queryHint,但它并没有改变颜色。 我认为使用的editTextColor 在我的默认应用样式中定义为

<item name="android:textColorPrimary">@color/color_text_primary</item>

&lt;color name="color_text_primary"&gt;#344d93&lt;/color&gt;

如果我在特定样式中设置了其他颜色,怎么会出现这种情况?

【问题讨论】:

    标签: android android-studio colors styles searchview


    【解决方案1】:

    对于自定义,您可以使用android:theme="@style/AppTheme.SearchView" 或动态使用此代码https://gist.github.com/jaredrummler/c408c9d897fd92d5d116

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-15
      • 1970-01-01
      • 2016-11-14
      • 2023-03-22
      • 1970-01-01
      • 2012-07-16
      相关资源
      最近更新 更多