0

検索バーは、(見えない)応答しているツールバーの内部で動作していないSearchviewは menu.xml私はツールバー内検索アイコンをクリックすると、アンドロイド

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

検索バーアクティブ性

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> 

私は私の後に、AppCompatActivity.Iは以前と同じコードを試してみましたし、私はそれが働いてしまっ拡張しましたstyles.xmlとv21/styles.xmlの内部で変更が加えられたため、これが問題になりました。ありがとう。

答えて

0

次のコードを使用 とSearchView.OnQueryTextListener

(あなたが解決策を取得する場合、も、あなたが同じに関連するより多くの助けを求めることができ、受け入れ答えとしてそれをマークしてください)あなたの要件に応じて他の操作を行う実装
SearchView searchView = (SearchView)menu.findItem(R.id.search).getActionView(); 
    int searchImgId = android.support.v7.appcompat.R.id.search_button; 
    ImageView v = (ImageView) searchView.findViewById(searchImgId); 
    searchView.setOnQueryTextListener(this); 
+0

こんにちは、返信ありがとう。私は上記のコードを試して、そのworking.Onceはstyles.xmlとv21/styles.xml.Iをチェックツールバーやテーマに問題があると思う。 –

+0

なぜあなたはをmanifest.xmlから削除してからコードを試してみますか –

+0

私はメタデータを削除してみました。データ、変更なし –

0

アクションとしてshowからcollapseActionViewを削除します。 ちょうど追加app:showAsAction="ifRoom"

+0

お返事ありがとうございます。私はifroomを試してみましたが、そのworking.Onceはstyles.xmlとv21/stylesを確認します。ツールバーやテーマに問題があると思います。 –

関連する問題