searchView输入的文字不可见
searchView's entered text is not visible
我在工具栏中的 searchView 没有显示 searchView 文本框中的文本,请看下图:
输入文本时,光标在移动,如下所示,但文本不可见
但是当我选择输入的文本时,现在您可以看到输入的文本,折叠 searchView 的图标也看不到(在 searchView 的左侧)知道为什么会这样吗???
我的 xml 文件:
<?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>
得到它的工作,感谢 Ferran Maylinch
for (TextView textView : findChildrenByClass(searchView, TextView.class)) {
textView.setTextColor(Color.WHITE);
}
url函数:
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;
}
我在工具栏中的 searchView 没有显示 searchView 文本框中的文本,请看下图:
输入文本时,光标在移动,如下所示,但文本不可见
但是当我选择输入的文本时,现在您可以看到输入的文本,折叠 searchView 的图标也看不到(在 searchView 的左侧)知道为什么会这样吗???
我的 xml 文件:
<?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>
得到它的工作,感谢 Ferran Maylinch
for (TextView textView : findChildrenByClass(searchView, TextView.class)) {
textView.setTextColor(Color.WHITE);
}
url函数:
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;
}