android中的搜索栏小部件?
android中的搜索栏小部件?,android,searchbar,Android,Searchbar,有没有像android默认搜索栏一样的搜索栏小部件?。我只想像默认的搜索栏,我要处理搜索功能。我可以通过使用编辑文本小部件来实现这一点,但我想知道是否有现成的小部件可用?您可以使用TextWatcher类使编辑文本像搜索栏一样工作。您可以使用TextWatcher类使编辑文本像搜索栏一样工作。请参见此处在您使用的onCreate方法中,请参见此处可以使用: onCreate方法: // enabling action bar app icon and behaving it as toggle
有没有像android默认搜索栏一样的搜索栏小部件?。我只想像默认的搜索栏,我要处理搜索功能。我可以通过使用编辑文本小部件来实现这一点,但我想知道是否有现成的小部件可用?您可以使用TextWatcher类使编辑文本像搜索栏一样工作。您可以使用TextWatcher类使编辑文本像搜索栏一样工作。请参见此处在您使用的onCreate方法中,请参见此处可以使用: onCreate方法:
// enabling action bar app icon and behaving it as toggle button
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
handleIntent(getIntent());
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.feed, menu);
// Associate searchable configuration with the SearchView
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.action_search)
.getActionView();
searchView.setSearchableInfo(searchManager
.getSearchableInfo(getComponentName()));
return true;
}
<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"
tools:context="br.com.srtorcedor.FeedActivity">
<item android:id="@+id/action_search"
android:icon="@drawable/abc_ic_search"
android:title="@string/search_title"
android:showAsAction="always"
android:actionViewClass="android.widget.SearchView"/>
</menu>
onCreateOptions菜单:
// enabling action bar app icon and behaving it as toggle button
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
handleIntent(getIntent());
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.feed, menu);
// Associate searchable configuration with the SearchView
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.action_search)
.getActionView();
searchView.setSearchableInfo(searchManager
.getSearchableInfo(getComponentName()));
return true;
}
<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"
tools:context="br.com.srtorcedor.FeedActivity">
<item android:id="@+id/action_search"
android:icon="@drawable/abc_ic_search"
android:title="@string/search_title"
android:showAsAction="always"
android:actionViewClass="android.widget.SearchView"/>
</menu>
菜单:
// enabling action bar app icon and behaving it as toggle button
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
handleIntent(getIntent());
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.feed, menu);
// Associate searchable configuration with the SearchView
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.action_search)
.getActionView();
searchView.setSearchableInfo(searchManager
.getSearchableInfo(getComponentName()));
return true;
}
<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"
tools:context="br.com.srtorcedor.FeedActivity">
<item android:id="@+id/action_search"
android:icon="@drawable/abc_ic_search"
android:title="@string/search_title"
android:showAsAction="always"
android:actionViewClass="android.widget.SearchView"/>
</menu>
这样,您将在操作栏上看到搜索小部件。我希望它能与你们一起工作。在您的onCreate方法中,您可以使用: onCreate方法:
// enabling action bar app icon and behaving it as toggle button
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
handleIntent(getIntent());
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.feed, menu);
// Associate searchable configuration with the SearchView
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.action_search)
.getActionView();
searchView.setSearchableInfo(searchManager
.getSearchableInfo(getComponentName()));
return true;
}
<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"
tools:context="br.com.srtorcedor.FeedActivity">
<item android:id="@+id/action_search"
android:icon="@drawable/abc_ic_search"
android:title="@string/search_title"
android:showAsAction="always"
android:actionViewClass="android.widget.SearchView"/>
</menu>
onCreateOptions菜单:
// enabling action bar app icon and behaving it as toggle button
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
handleIntent(getIntent());
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.feed, menu);
// Associate searchable configuration with the SearchView
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.action_search)
.getActionView();
searchView.setSearchableInfo(searchManager
.getSearchableInfo(getComponentName()));
return true;
}
<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"
tools:context="br.com.srtorcedor.FeedActivity">
<item android:id="@+id/action_search"
android:icon="@drawable/abc_ic_search"
android:title="@string/search_title"
android:showAsAction="always"
android:actionViewClass="android.widget.SearchView"/>
</menu>
菜单:
// enabling action bar app icon and behaving it as toggle button
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
handleIntent(getIntent());
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.feed, menu);
// Associate searchable configuration with the SearchView
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.action_search)
.getActionView();
searchView.setSearchableInfo(searchManager
.getSearchableInfo(getComponentName()));
return true;
}
<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"
tools:context="br.com.srtorcedor.FeedActivity">
<item android:id="@+id/action_search"
android:icon="@drawable/abc_ic_search"
android:title="@string/search_title"
android:showAsAction="always"
android:actionViewClass="android.widget.SearchView"/>
</menu>
这样,您将在操作栏上看到搜索小部件。我希望它能与你们一起工作。您如何在doSearch方法中进行搜索您没有提供setIntent()您如何在doSearch方法中进行搜索您没有提供setIntent()