2016-07-15 84 views
1

我正在使用搜索视图。它之前工作,它没有响应,我不能看到在搜索视图中输入的任何文本,也不会在文本发生更改时收回任何回调。Android搜索查看未显示任何文本

这里是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> 

这里是我如何设置搜索查看回调,

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); 

我没有得到任何回调这些方法,当我在搜索查看类型。

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

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

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

谢谢。

+0

您是否试过我的解决方案? –

+0

请显示'filterCards(newText);' –

+0

@SohailZahid当我输入到SearchView时从未触发该方法 – Zach

回答

0

尽量给,

android:textColor="#000000" 

android.support.v7.widget.SearchView

Note :可能是你的文字是白色的,这就是为什么你不能看到。

+0

我不认为它的文字颜色,正如你所看到的,我正在改变代码中的文字颜色。我也试过你的解决方案。没有工作。如果它的文字颜色,那么我应该回调给侦听器方法。那没有发生 – Zach