开发者

Android : Activate SearchDialog from Action bar

I've implemented the action bar found here https://github.com/johannilsson/an开发者_如何学Godroid-actionbar and it works beautifully. However, I've added a search button and can't get it to show the search dialog. I followed the Google's search dialog tutorial to set my project up, but the dialog just won't show up. Any help?

Manifest:

<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>

Action Bar setup:

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, intent, R.drawable.ic_title_export_default));

intent = new Intent().setClass(this, OtherActivity.class);
actBar.addAction(new ActionBar.IntentAction(this, intent, R.drawable.ic_title_search_default));

OtherActivity:

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>


Action Bar Setup

actionBar.addAction(new SearchMP());

private class SearchMP extends AbstractAction {

    public SearchMP() {
        super(R.drawable.title_search);
    }

    @Override
    public void performAction(View view) {
        onSearchRequested();
    }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜