改变SearchViewbutton的背景颜色和查询

出于某种原因,我的searchview有一个白色的背景,而不是透明的,我似乎不能摆脱它。 我正在使用AppCompat主题。 我手动使用ToolBar作为我的ActionBar

menu.xml文件

 <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/search" android:title="Search" android:icon="@android:drawable/ic_menu_search" app:showAsAction="collapseActionView|ifRoom" app:actionViewClass="com.exposure.controls.ExposureSearchView" /> </menu> 

在这里输入图像说明

 <style name="LaunchTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="android:colorBackground">@color/app_background</item> <item name="android:windowContentOverlay">@null</item> <item name="android:background">@android:color/transparent</item> <item name="windowActionBarOverlay">true</item> <item name="android:windowActionBarOverlay">true</item> <item name="android:windowFullscreen">true</item> <item name="windowNoTitle">true</item> <item name="windowActionBar">false</item> <item name="searchViewStyle">@style/MySearchViewStyle</item> </style> <style name="MySearchViewStyle" parent="Widget.AppCompat.SearchView"> <item name="queryBackground">@android:color/transparent</item> <item name="submitBackground">@android:color/transparent</item> </style> 

Solutions Collecting From Web of "改变SearchViewbutton的背景颜色和查询"

我更新了这些背景透明,它的工作。

 <style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid"> <item name="android:background" tools:ignore="NewApi">@android:color/transparent</item> <item name="background">@android:color/transparent</item> 

我不确定它是否会起作用,请将<item name="android:background">@android:color/transparent</item>更改为<item name="android:background">@color/app_background</item>在你的发射主题

试试这个方法

 <style name="searchButtonStyle" parent="Widget.AppCompat.Light.ActionButton.Overflow"> <item name="android:background">@color/your_color</item> <item name="background">@color/your_color</item> </style> 

把这添加到你的风格,如

 <style name="LaunchTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="android:actionOverflowButtonStyle">@style/searchButtonStyle</item> <item name="actionOverflowButtonStyle">@style/searchButtonStyle</item> </style> 
  SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.menu_search)); SearchManager searchManager = (SearchManager) getSystemService(Activity.SEARCH_SERVICE); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); // Setting up custom search button icon int searchImgId = android.support.v7.appcompat.R.id.search_button; // I used the explicit layout ID of searchview's ImageView // Use Whatever icon you want over here in place of ic_search_black ImageView v = (ImageView) searchView.findViewById(searchImgId); v.setImageResource(R.drawable.ic_search_black); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { // Do operation return true; } @Override public boolean onQueryTextChange(String newText) { return false; } });