【问题标题】:Android Search View not displaying any textAndroid 搜索视图不显示任何文本
【发布时间】:2016-07-15 12:24:35
【问题描述】:

我正在使用搜索视图。它之前一直在工作,但现在没有响应,我看不到在搜索视图中输入的任何文本,当文本更改时我也没有收到任何回叫。

这里是xml布局文件,

<LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.SearchView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:iconifiedByDefault="false"
            android:id="@+id/searchView"/>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/cardsRecyclerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/transparent"
            android:cacheColorHint="@android:color/transparent"/>
    </LinearLayout>

这是我设置 SearchView 回调的方式,

EditText searchEditText = (EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
        searchEditText.setTextColor(getResources().getColor(R.color.colorPrimary));
        searchEditText.setHintTextColor(getResources().getColor(R.color.dark_grey));
searchView.setOnQueryTextListener(this);

当我输入 SearchView 时,我没有收到对这些方法的任何回调。

@Override
    public boolean onQueryTextSubmit(String query) {
        return false;
    }

    @Override
    public boolean onQueryTextChange(String newText) {
        filterCards(newText);
        return false;
    }

我正在我的 Fragment 中实现 SearchView.OnQueryTextListener。

谢谢。

【问题讨论】:

  • 你试过我的解决方案了吗?
  • 请显示filterCards(newText);
  • @SohailZahid 当我输入 SearchView 时,该方法永远不会触发

标签: android searchview


【解决方案1】:

尝试给予,

 android:textColor="#000000"

致您的android.support.v7.widget.SearchView

Note :可能是你的文字是白色的,所以你看不到。

【讨论】:

  • 我不认为它是文本颜色,如您所见,我正在更改代码中的文本颜色。我也试过你的解决方案。没用。如果它是文本颜色,那么我应该回调监听器方法。那没有发生
猜你喜欢
  • 2019-11-03
  • 2015-01-06
  • 1970-01-01
  • 2017-09-25
  • 2016-01-04
  • 1970-01-01
  • 1970-01-01
  • 2021-09-24
  • 1970-01-01
相关资源
最近更新 更多