简体   繁体   English

如何在Light Appcompat主题中使用来自黑暗主题的SearchView

[英]How to use SearchView from dark theme in Light Appcompat theme

I am using Theme.AppCompat.Light theme and using SearchView which by default shows dark texts and icons.. 我正在使用Theme.AppCompat.Light主题并使用SearchView,它默认显示深色文本和图标。

How can I use SearchView defined in Theme.AppCompat in this light theme? 如何在这个光主题中使用Theme.AppCompat中定义的SearchView?

Already tried below but not working? 已经尝试过以下但没有工作?

<style name="Theme.App.Light" parent="Theme.AppCompat.Light">
   <item name="searchViewStyle">@style/Widget.AppCompat.SearchView</item>
</style> 

Even using Theme.AppCompat.Light.DarkActionBar as base theme does not show the white texts and icons.. 即使使用Theme.AppCompat.Light.DarkActionBar作为基本主题也不会显示白色文本和图标..

It can be done by overriding all values,but I just need to use defaults provided in Dark theme.. 它可以通过覆盖所有值来完成,但我只需要使用Dark主题中提供的默认值。

Per this pro-tip , Theme.AppCompat.Light.DarkActionBar only applies if you are using the AppCompat provided Action Bar. 根据这个专业提示Theme.AppCompat.Light.DarkActionBar仅适用于您使用AppCompat提供的Action Bar。 If you are using a Toolbar , then you should be using a Theme.AppCompat.Light.NoActionBar theme. 如果您使用的是Toolbar ,那么您应该使用Theme.AppCompat.Light.NoActionBar主题。 To theme your Toolbar appropriate for a dark background, you need to add android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" : 要设置适合深色背景的工具栏,需要添加android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"

<android.support.v7.widget.Toolbar
    android:background="?attr/colorPrimary"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>

SearchView will then pull the correct resources needed to work on a dark background. 然后, SearchView将提取在深色背景上工作所需的正确资源。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM