【问题标题】:How can I use Light SearchView on Dark App Bar on android?如何在 android 上的 Dark App Bar 上使用 Light SearchView?
【发布时间】:2016-01-27 17:03:45
【问题描述】:

这是我的主要活动 xml:

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_main" />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    android:src="@android:drawable/ic_menu_search" />

这是我的styles.xml

<style name="AppTheme" parent="Theme.AppCompat.Light">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
</style>

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

问题是我想在 AppBar 上使用白色文本,但同时我希望搜索建议在白色背景上有深色文本(如全息)。目前,建议以深色主题显示。如果我使用 ThemeOverlay.AppCompat.ActionBar,那么建议会变成白色,但 appbar 上的文本会变成黑色,我希望它保持白色。

请帮帮我!我还附上屏幕截图用于演示目的:

  1. 这有白色的标题文本。
  2. 看到下拉建议了吗?它们应该以白色为主题。

【问题讨论】:

    标签: android material-design android-theme searchview android-appbarlayout


    【解决方案1】:

    这是我成功实现这一目标的方法:

    您需要在您的主题中覆盖样式 autoCompleteTextViewStyletextAppearanceSearchResultTitle

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="autoCompleteTextViewStyle">@style/myAutoCompleteTextViewStyle</item>
        <item name="textAppearanceSearchResultTitle">@style/mySearchResult</item>
    
        ...
    </style>
    
    <style name="myAutoCompleteTextViewStyle" parent="Widget.AppCompat.Light.AutoCompleteTextView">
        <item name="android:popupBackground">@color/White</item>
    </style>
    
    <style name="mySearchResult" parent="TextAppearance.AppCompat.SearchResult.Title">
        <item name="android:textColor">@color/Black</item>
    </style>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-24
      • 2014-04-13
      • 1970-01-01
      • 1970-01-01
      • 2014-06-16
      相关资源
      最近更新 更多