问题描述
|
我已经实现了在https://github.com/johannilsson/android-actionbar上找到的操作栏,并且效果很好。但是,我添加了一个搜索按钮,但无法显示搜索对话框。我遵循了Google \的搜索对话框教程来设置我的项目,但是该对话框不会显示。有什么帮助吗?
表现:
<activity android:name=\".HomeActivity\" android:label=\"Intelicase Mobile\" android:clearTaskOnLaunch=\"true\">
<intent-filter>
<action android:name=\"android.intent.action.MAIN\" />
<category android:name=\"android.intent.category.LAUNCHER\" />
</intent-filter>
<!-- enable the search dialog to send searches to SearchableActivity -->
<Meta-data android:name=\"android.app.default_searchable\"
android:value=\".SearchActivity\" />
</activity>
<activity android:name=\".SearchActivity\" 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>
<Meta-data android:name=\"android.app.default_searchable\"
android:value=\".SearchActivity\" />
<!-- this activity enables the search dialog to initiate searches in the SearchableActivity -->
<activity android:name=\".OtherActivity\">
<Meta-data android:name=\"android.app.default_searchable\"
android:value=\".SearchActivity\" />
</activity>
动作栏设置:
ActionBar actBar = (ActionBar) findViewById(R.id.actionbar);
actBar.setTitle(\"Dashboard\");
actBar.setHomeAction(new ActionBar.IntentAction(HomeActivity.this,intent,R.drawable.ic_title_home_default));
intent = new Intent().setClass(this,CaseEvidenceActivity.class);
actBar.addAction(new ActionBar.IntentAction(this,R.drawable.ic_title_export_default));
intent = new Intent().setClass(this,OtherActivity.class);
actBar.addAction(new ActionBar.IntentAction(this,R.drawable.ic_title_search_default));
其他活动:
public class OtherActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search);
onSearchRequested();
}
}
searchables.xml:
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<searchable xmlns:android=\"http://schemas.android.com/apk/res/android\"
android:label=\"Intelicase Mobile\"
android:hint=\"Search Intelicase\" android:searchSuggestAuthority=\"dictionary\"
android:searchSuggestIntentAction=\"android.intent.action.VIEW\">
</searchable>
解决方法
动作栏设置
actionBar.addAction(new SearchMP());
private class SearchMP extends AbstractAction {
public SearchMP() {
super(R.drawable.title_search);
}
@Override
public void performAction(View view) {
onSearchRequested();
}
}