本文介绍了widget.SearchView在Android中未显示用于语音搜索的MIC按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在名为activity_products_final的布局文件中有一个seachview
I have a seachview in layout file named activity_products_final
<android.support.v7.widget.SearchView
android:id="@+id/searchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:queryHint="Search..">
</android.support.v7.widget.SearchView>
</LinearLayout>
活动:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_products_final);
searchView = (android.support.v7.widget.SearchView) findViewById(R.id.searchView);
searchView.setIconified(false);
searchView.onActionViewExpanded();
searchView.clearFocus();
searchView.setOnQueryTextListener(new android.support.v7.widget.SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
if (adapter != null)
filterData(query);
return false;
}
@Override
public boolean onQueryTextChange(String query) {
if (adapter != null)
filterData(query);
return false;
}
});
ImageView closeButton = (ImageView) searchView.findViewById(R.id.search_close_btn);
closeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
searchView.setQuery("", false);
searchView.clearFocus();
//collapseAll();
}
});
}
清单文件
<activity
android:name=".ActivityProductList"
android:configChanges="orientation|screenSize"
android:label="@string/title_activity_products"
android:launchMode="singleTop"
android:parentActivityName=".ActivityStartShopping"
android:screenOrientation="portrait"
>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
xml/searchable
xml/searchable
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/app_name"
android:hint="@string/search_hint"
android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"
>
</searchable>
根据Google文档,我必须使用android:voiceSearchMode ="showVoiceSearchButton | launchRecognizer"来显示MIC按钮.
As per google docs i have to use android:voiceSearchMode="showVoiceSearchButton|launchRecognizer" to show MIC button.
我关注了该文档,但没有显示MIC按钮来捕获语音输入.
I followed the doc but it is not showing MIC button to capture voice input.
有人可以帮我吗?
推荐答案
您需要创建 SearchableConfiguration .将其添加为xml资源文件夹中的 searchable.xml
:
You need to create a SearchableConfiguration. Add this as searchable.xml
in your xml resource folder:
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:hint="search..."
android:label="@string/app_name"
<!-- the next line enables the voice button display -->
android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"/>
这篇关于widget.SearchView在Android中未显示用于语音搜索的MIC按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!