我现在已经坚持了一段时间.我看过其他答案,SO
但他们没有帮助我解决我的问题.
我的问题是没有调用搜索对话框onSearchRequested()
.我无法弄清楚我的搜索是怎么回事......
相关代码如下......
表现
<activity
android:name=".SearchableActivity"
android:label="@string/app_name"
android:launchMode="singleTop" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
Run Code Online (Sandbox Code Playgroud)
/res/xml/searchable.xml
<?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" >
</searchable>
Run Code Online (Sandbox Code Playgroud)
我有定义的字符串资源strings.xml
.
SearchableActivity类
public class SearchableActivity extends ListActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d("SEARCH", "HERE");
handleIntent(getIntent());
}
public void onNewIntent(Intent intent) {
setIntent(intent);
handleIntent(intent);
}
public void onListItemClick(ListView l, View v, int position, long id) {
// call the appropriate detail activity
}
private …
Run Code Online (Sandbox Code Playgroud) 我想知道Android中搜索对话框和搜索窗口小部件之间的区别.我知道如何使用代码实现每个代码,但不了解外观,行为等方面的差异.任何帮助都将受到高度赞赏.
根据新的材料设计更新,Google付款商店应用操作搜索会在搜索操作按钮上打开一个搜索对话框.此搜索界面与android在操作栏中提供的默认操作视图不同(仅在操作栏中打开).
所以我的问题是如何实现像google play store app这样的新搜索操作对话框.是否有任何Android官方组件或我必须为此创建自定义对话框视图?如果是第二个,那么请说明如何实现这种类型的搜索视图?
search android android-actionbar search-dialog material-design
根据官方文档,有两种方法可以提供搜索界面:使用搜索对话框或SearchView
小部件.我想注意使用这两种方式传递搜索上下文数据.
所以,文档说:
..您可以提供系统发送给您的可搜索活动的意图中的其他数据.您可以传递APP_DATA包中的附加数据,该包含在ACTION_SEARCH目的中.
要将此类数据传递给可搜索的活动,请覆盖用户可以执行搜索的活动的onSearchRequested()方法,使用其他数据创建Bundle,并调用startSearch()以激活搜索对话框.例如:
Run Code Online (Sandbox Code Playgroud)@Override public boolean onSearchRequested() { Bundle appData = new Bundle(); appData.putBoolean(SearchableActivity.JARGON, true); startSearch(null, false, appData, false); return true; }
..一旦用户提交查询,它就会与您添加的数据一起发送到您的可搜索活动.您可以从APP_DATA Bundle中提取额外数据以优化搜索.例如:
Run Code Online (Sandbox Code Playgroud)Bundle appData = getIntent().getBundleExtra(SearchManager.APP_DATA); if (appData != null) { boolean jargon = appData.getBoolean(SearchableActivity.JARGON); }
这是指搜索对话框.那么搜索小部件呢?
是否可以SearchView
仅使用小部件传递搜索上下文数据?
希望,有人可以给出明确的解释和/或建议另一种或类似的方式来实现目标.
谢谢!
android android-intent android-searchmanager searchview search-dialog