Searchbar (nicht sichtbar) reagiert, wenn ich auf das Symbol Suche klicken Sie in der Symbolleiste menu.xmlSuche arbeiten nicht in Symbolleiste android
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/search"
android:title="search_title"
android:icon="@drawable/search"
app:showAsAction="collapseActionView|ifRoom"
android:actionViewClass="android.widget.SearchView" />
searchable.xml
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/app_name"
android:hint="search_hint" />
manifestfile
<activity
android:name=".SearchbarActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<!-- This metadata entry provides further configuration details for searches -->
<!-- that are handled by this activity. -->
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
searchbaractivity
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_search, menu);
SearchManager searchManager = (SearchManager)
getSystemService(Context.SEARCH_SERVICE);
MenuItem searchMenuItem = menu.findItem(R.id.search);
SearchView searchView = (SearchView) searchMenuItem.getActionView();
return true;
}
v21/styles.xml
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowContentTransitions">true</item>
<item name="android:windowActivityTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">false</item>
<item name="android:windowAllowReturnTransitionOverlap">false</item>
</style>
styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="Splash" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/splashscreen</item>
</style>
Ich habe AppCompatActivity.I haben den gleichen Code früher versucht, erweitert und ich habe es funktioniert, danach i habe Änderungen in styles.xml und v21/styles.xml vorgenommen, ich glaube das hat das Problem gemacht. Danke.
Hey, danke für die Antwort.Ich habe versucht, den oben genannten Code, es funktioniert nicht.Kontrollieren Sie die styles.xml und v21/styles.xml.Ich denke, es gibt ein Problem in Toolbar oder Theme. –
Warum verwenden Sie versuchen Sie den Code, nachdem Sie ihn aus der Datei manifest.xml entfernt haben –
Ich habe versucht, indem ich Meta- Daten, keine Änderung –