带麦克风和麦克风事件的Android搜索栏. Android搜索视图与麦克风
作者:互联网
我在我的应用程序中使用searchview.我想在searchview文本框中输入文本并将其显示在另一个textview上.
我可以使用searchviewListener来做到这一点.
searchView.setOnQueryTextListener(new android.support.v7.widget.SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
//adapter.filterData(query);
//display text where ever i want
return false;
}
@Override
public boolean onQueryTextChange(String query) {
adapter.filterData(query);
//display text where ever i want
return false;
}
});
return true;
}
现在我使用Mic制作了serachView
android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"
麦克风正在显示并可点击.完善..
现在我的问题是如何捕获这个MIC数据并在任何我想要的地方显示文本.
解决方法:
为了显示从MIC捕获的数据,我试图在android developer link的帮助下给出答案.
正如你提到的那样,
*麦克风正在显示和点击.完美..如何捕获此MIC数据并显示我想要的文本. *
您需要为Seachable& amp; xml资源相同.
获取麦克风捕获的数据(将作为对话框打开),而不是在检查意图动作后需要在活动的onNewIntent中处理它的数据Intent.ACTION_SEARCH
search_voice.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/ab_tool"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00FFFFFF"
android:minHeight="?attr/actionBarSize">
</android.support.v7.widget.Toolbar>
<TextView
android:id="@+id/txtVoiceSeachQuery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FF0000"
android:textSize="26sp" />
</LinearLayout>
SearchVoiceTest
public class SearchVoiceTest extends AppCompatActivity {
private TextView txtVoiceSeachQuery;
private SearchView searchView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search_voice);
Toolbar toolbar = (Toolbar) findViewById(R.id.ab_tool);
setSupportActionBar(toolbar);
toolbar.setTitle("Voice Text Display");
txtVoiceSeachQuery = (TextView) findViewById(R.id.txtVoiceSeachQuery);
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
searchView.setQuery(String.valueOf(query), false);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_home_screen, menu);
searchView =
(SearchView) menu.findItem(R.id.search_view).getActionView();
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setOnQueryTextListener(new android.support.v7.widget.SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
//adapter.filterData(query);
//display text where ever i want
return false;
}
@Override
public boolean onQueryTextChange(String query) {
//display text where ever i want
if (txtVoiceSeachQuery != null) {
txtVoiceSeachQuery.setText(query);
}
return false;
}
});
return true;
}
}
AndroidManifest宣传活动
<activity
android:name="com.example.search.voice.SearchVoiceTest"
android:configChanges="orientation|screenSize"
android:launchMode="singleTop" android:label="Search Voice Test"
android:theme="@style/AppThemeSliderToolbar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/search_with_voice" />
</activity>
RES / XML / search_with_voice.xml
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:hint="Give Your Query Here"
android:label="@string/app_name"
android:voiceSearchMode="showVoiceSearchButton|launchRecognizer">
</searchable>
RES /菜单/ menu_home_screen.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
>
<item
android:id="@+id/search_view"
android:title="Search"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="ifRoom|collapseActionView"></item>
</menu>
在为seachview分配查询后,我们可以在onQueryTextChange中获取回调setOnQueryTextListener,以便从那里获得分配给TextView的测试目的值,您可以进行更改.
在这里,我给出了答案的输出链接.
> Search with voice
> Display Captured data from mic
如果有的话,让我知道
标签:android,android-layout,searchview,android-search 来源: https://codeday.me/bug/20190528/1167997.html