22029

Theme for SearchView in ActionBar

Question:

I have a SearchView in an ActionBar.

This SearchView icon is black, and text is black too whereas my icon is white !

<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/action_search" android:title="@string/menu_search" android:icon="@drawable/ic_search" app:actionViewClass="android.support.v7.widget.SearchView" app:showAsAction="always" /> </menu>

I would like my SearchView be white.

Answer1:

Here in menu.xml add,

<item android:id="@+id/action_search" android:icon="@drawable/icon" android:title="Search" app:actionViewClass="android.support.v7.widget.SearchView" app:showAsAction="always"/>

in style.xml you need to apply style like this

<style name=”Theme.MyTheme” parent=”Theme.AppCompat”> <item name=”searchViewStyle”>@style/MySearchViewStyle</item> </style> <style name=”MySearchViewStyle” parent=”Widget.AppCompat.SearchView”> <!-- Background for the search query section (e.g. EditText) --> <item name="queryBackground">...</item> <!-- Background for the actions section (e.g. voice, submit) --> <item name="submitBackground">...</item> <!-- Close button icon --> <item name="closeIcon">...</item> <!-- Search button icon --> <item name="searchIcon">...</item> <!-- Go/commit button icon --> <item name="goIcon">...</item> <!-- Voice search button icon --> <item name="voiceIcon">...</item> <!-- Commit icon shown in the query suggestion row --> <item name="commitIcon">...</item> <!-- Layout for query suggestion rows --> <item name="suggestionRowLayout">...</item> </style>

and finally in menifest file:

<application... android:theme="@style/Theme.MyTheme" >

Ref: <a href="http://android-developers.blogspot.in/2014/10/appcompat-v21-material-design-for-pre.html" rel="nofollow">Android appcompact library</a> Hope this helped!

Recommend

  • Internal interfaces - exposing my ignorance
  • Android: Inflate menu (add items to action bar) only on click of a button
  • Submiting a Form is returning application/json instead of text/html
  • Change Design Support Navigation View Header Title Programmatically
  • jinja2 template not found and internal server error
  • In Akka, is ActorContext thread safe?
  • write text on image and show it to a imageview
  • How to remove all of a jQuery UI dialog when it is closed
  • How to stamp out template in self contained custom elements with vanilla js?
  • Unable to resolve Static method?
  • Creating a Multi-Step Modal Using Jquery
  • Outputting SharePoint Hyperlink Column as URL
  • Form tag not showing up in haml file
  • How to explicitly/implicitly implemented interface members in C++/CLI?
  • Hibernate to update table schema
  • How to pass a value from ASP.NET MVC controller to ASP.NET webforms control inside MVC View?
  • Kendo barchart category labels left and right based on value
  • Roxygen error “Skipping invalid path”
  • wxPython: displaying multiple widgets in same frame
  • Jackson Parser: ignore deserializing for type mismatch
  • OpenGL 3.3 on Mac OSX El Capitan with LWJGL
  • Change multiple background-images with jQuery
  • MongoDB in PHP using aggregate to group by _id is null not working
  • Display issues when we change from one jquery mobile page to another in firefox
  • Can Jackson SerializationFeature be overridden per field or class?
  • Trying to switch camera back to front but getting exception
  • Arrow is showed instead of the material design version hamburger icon. Why doesn't syncState in
  • To display the title for the current loaction in map in iphone
  • jquery mobile loadPage not working
  • AT Commands to Send SMS not working in Windows 8.1
  • How to delete a row from a dynamic generate table using jquery?
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • json Serialization in asp
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • trying to dynamically update Highchart column chart but series undefined
  • NSLayoutConstraint that would pin a view to the bottom edge of a superview
  • How to stop GridView from loading again when I press back button?
  • apache spark aggregate function using min value
  • Sorting a 2D array using the second column C++
  • How to push additional view controllers onto NavigationController but keep the TabBar?