Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change background color of SearchView button and query

For some reason my searchview has a white background instead of transparent and I cant seem to get rid of it. I am using AppCompat theme. I am using a ToolBar manually as my 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>

enter image description here

<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>
like image 704
Mike Flynn Avatar asked Dec 20 '16 19:12

Mike Flynn


People also ask

How do I change the color on SearchView?

Change the text colors and icons of searchview in action bar. Expand the search view by setting iconified and iconifiedByDefault flags to false. Find views inside the search view and set the colors as per your wish. Find views of the icons you wish to change and replace them with your icons.

How can change background color of button in XML?

To set Android Button background color, we can assign android:backgroundTint XML attribute for Button in layout file with the required Color Value. To programmatically set or change Android Button background color, we may call pass the method Button.

What is SearchView?

androidx.appcompat.widget.SearchView. A widget that provides a user interface for the user to enter a search query and submit a request to a search provider.


1 Answers

I updated these backgrounds to transparent and it worked.

<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>
like image 121
Mike Flynn Avatar answered Sep 21 '22 00:09

Mike Flynn