0

I added a SearchView to my toolbar like this:

    MenuItem searchMenuItem = menu.findItem(R.id.action_search);
    mSearchView = (SearchView) searchMenuItem.getActionView();

The XML is:

<item
    android:id="@+id/action_search"
    android:icon="@drawable/ic_search"
    android:title="@string/action_search"
    app:actionViewClass="androidx.appcompat.widget.SearchView"
    app:showAsAction="ifRoom|collapseActionView" />

I experience a weird behavior in one of my activities. At first, the toolbar looks like this:

enter image description here

When I click on the SearchView icon, the toolbar suddenly changes to:

enter image description here

Here, the color of the back button and the color of the hint text change to black. However, I want it to stay white just like the original (unclicked) toolbar. My styles are:

<style name="OfferingsMaterialTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <item name="colorAccent">@color/accent</item>
    <item name="windowActionModeOverlay">true</item>
    <item name="actionOverflowButtonStyle">@style/OverFlow</item>
    <item name="android:textColorHint">@color/material_white_60_opacity</item>
    <item name="actionBarTheme">@style/ToolbarTheme</item>
</style>
<style name="OfferingsMaterialTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="OverFlow" parent="Widget.AppCompat.ActionButton.Overflow">
    <item name="android:tint">@color/icons</item>
</style>
<style name="ToolbarTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
    <item name="colorControlNormal">@color/material_white_1000</item>
    <item name="android:textColorHint">@color/material_white_60_opacity</item>
</style>

This is my toolbar style:

<androidx.appcompat.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="?android:attr/colorPrimary"
app:titleTextColor="@color/icons"
app:title="@string/offeringsfragment_title"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

I have tried a few suggested solutions such as this. None of it works. Can anyone help?

to_sam
  • 695
  • 8
  • 19

0 Answers0