简体   繁体   English

如何在Android上的Dark App Bar上使用Light SearchView?

[英]How can I use Light SearchView on Dark App Bar on android?

This is my main activity xml: 这是我的主要活动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" />

This is my styles.xml 这是我的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" />

The problem is that I want to use white text on the AppBar, but at the same time I want the search suggestions to have dark text on white background (like holo). 问题是我想在AppBar上使用白色文本,但同时我希望搜索建议在白色背景上具有深色文本(如全息)。 Currently the suggestions are shown in dark theme. 目前,建议以深色主题显示。 If I use ThemeOverlay.AppCompat.ActionBar, then the suggestions turn white but the text on appbar is turned Black, and I want it to remain white. 如果我使用ThemeOverlay.AppCompat.ActionBar,则建议将变为白色,但appbar上的文本将变为黑色,并且我希望它保持白色。

Please help me! 请帮我! I am also attaching screenshots for demonstration purposes: 我还附有屏幕截图以进行演示:

  1. This has white title text. 它具有白色标题文本。
  2. see the dropdown suggestions? 看到下拉建议吗? they should be white-themed. 他们应该以白色为主题。 标题文字为白色 看到下拉建议吗?他们应该以白色为主题。

Here is how I succeeded to achieve that: 这是我成功实现的方式:

You need to override the styles autoCompleteTextViewStyle and textAppearanceSearchResultTitle in your theme: 您需要在主题中覆盖样式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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Light Appcompat主题中使用来自黑暗主题的SearchView - How to use SearchView from dark theme in Light Appcompat theme 如何更改工具栏searchView下拉菜单主题,使其在android应用中轻巧 - how can I change toolbar searchView drop down menu theme to be light in android app 如何使应用程序具有黑暗和明亮的主题? - How can I make an app dark and light theme? android searchView在操作栏中如何使用? - android searchView in action bar how to use it? Android 浅色/深色主题操作栏文字 - Android light/dark theme action bar text Android M Light and Dark status bar programmatically - 如何让它再次变暗? - Android M Light and Dark status bar programmatically - how to make it dark again? 如何将android按钮更改为深灰色而不是浅灰色 - How can I change the android button to dark grey instead of light grey 如果我的手机处于浅色或深色模式,如何制作带有文本和背景颜色的 Android 启动画面? - How can I make an Android splash screen with text & background color that changes if my phone is in light or dark mode? 如何向我的 Android 应用程序添加搜索视图? - How can I add a searchview to my Android app? 在同一应用中同时使用浅色和深色复选框 - Use both light and dark checkboxes in same app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM