Android : Suchen-button der Action Bar

Ich habe versucht, die Umsetzung der Aktions-Leiste mit einem Suchfeld, basierend auf den offiziellen android tuto (http://developer.android.com/training/search/setup.html)

Hier meine Dateien :

Manifest-Datei:

  <application
...
  android:theme="@style/Theme.AppCompat.Light" >

 <activity
            android:name=".activities.MainActivity"
            android:label="@string/title_activity_main" >
            <meta-data
                android:name="android.app.searchable"
                android:resource="@xml/searchable" />
        </activity>

   <activity
        android:name=".activities.SearchActivity"
        android:configChanges="orientation|keyboardHidden"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="stateHidden" >
          <intent-filter>
            <action android:name="android.intent.action.SEARCH" />
        </intent-filter>
    </activity>

...

</application>

(meta-Daten vorhanden sind)

MainActivity:

@Override
public boolean onCreateOptionsMenu(Menu menu) {

     //Inflate the menu; this adds items to the action bar if it is present.
     MenuInflater inflater = getMenuInflater();
     inflater.inflate(R.menu.action_bar_menu, menu);

    //Searchable configuration
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();    //MenuItemCompat.
    searchView.setSearchableInfo( searchManager.getSearchableInfo(getComponentName()));

    return super.onCreateOptionsMenu(menu);

}

action_bar_menu.xml :

<item
    android:id="@+id/search"
    android:icon="@drawable/ic_action_search"
    android:title="@string/menu_search"
    yourapp:actionViewClass="android.support.v7.widget.SearchView"
    yourapp:showAsAction="always"/>

res/xml/searchable.xml:

<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:hint="my hint"
    android:label="@string/app_name" />

Action-bar und der Suche-button angezeigt. Ich kann die input-Daten, sondern beim Klick auf den suchen-button (virtuelle Tastatur), nichts hängt.

Irgendwelche Ideen ?
Danke

InformationsquelleAutor johann | 2014-01-21
Schreibe einen Kommentar