remy boys
remy boys

Reputation: 2958

searchView's entered text is not visible

my searchView which is in a toolbar is not showing the texts which is inside the searchView's textBox please see the below image :

when am entering text the cursor is moving as you can see below but the text is not visible

enter image description here

but when am selecting the entered text , now you can see the entered text , the icon for collapsing searchView is also no visible (which is here at the left side of searchView ) any idea why is this happening ???

enter image description here

my xml file :

<?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:icon="@drawable/icon_search"
        app:actionViewClass="android.support.v7.widget.SearchView"
        app:showAsAction="ifRoom|collapseActionView"
        android:title="Search"/>

</menu>

Upvotes: 2

Views: 487

Answers (1)

remy boys
remy boys

Reputation: 2958

got it working , thanks to Ferran Maylinch

        for (TextView textView : findChildrenByClass(searchView, TextView.class)) {
            textView.setTextColor(Color.WHITE);
        }

the url function:

public static <V extends View> Collection<V> findChildrenByClass(ViewGroup viewGroup, Class<V> clazz) {

    return gatherChildrenByClass(viewGroup, clazz, new ArrayList<V>());
}

private static <V extends View> Collection<V> gatherChildrenByClass(ViewGroup viewGroup, Class<V> clazz, Collection<V> childrenFound) {

    for (int i = 0; i < viewGroup.getChildCount(); i++)
    {
        final View child = viewGroup.getChildAt(i);
        if (clazz.isAssignableFrom(child.getClass())) {
            childrenFound.add((V)child);
        }
        if (child instanceof ViewGroup) {
            gatherChildrenByClass((ViewGroup) child, clazz, childrenFound);
        }
    }

    return childrenFound;
}

Upvotes: 1

Related Questions