Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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..

How can I use SearchView defined in Theme.AppCompat in this light theme?

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..

It can be done by overriding all values,but I just need to use defaults provided in Dark theme..

like image 777
Awesome Avatar asked Jul 07 '15 17:07

Awesome


People also ask

What is theme AppCompat?

The AppCompat support library provides themes to build apps with the Material Design specification. A theme with a parent of Theme. AppCompat is also required for an Activity to extend AppCompatActivity . The first step is to customize your theme's color palette to automatically colorize your app.


1 Answers

Per this pro-tip, Theme.AppCompat.Light.DarkActionBar only applies if you are using the AppCompat provided Action Bar. If you are using a Toolbar, then you should be using a Theme.AppCompat.Light.NoActionBar theme. To theme your Toolbar appropriate for a dark background, you need to add 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.

like image 94
ianhanniballake Avatar answered Sep 21 '22 03:09

ianhanniballake