SearchView icon shows twice












0















I've implemented SearchView inside my toolbar, following Android's official instructions.



SearchView works well itself, but when I tap the search icon, it is shifted to the left instead of showing the Search Hint and Close button, although if I click this "second Search" icon, finally I get the typical search view.



Here is my xml of the toolbar:



<item android:id="@+id/search"
android:title="@string/search_view"
app:showAsAction="collapseActionView|ifRoom"
android:iconTint="@android:color/white"
android:icon="@drawable/ic_search_white_24dp"
app:actionViewClass="android.widget.SearchView" />


And my onCreateOptionsMenu



@Override
public boolean onCreateOptionsMenu(Menu menu) {

MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.options_menu, menu);

// Associate searchable configuration with the SearchView
SearchManager searchManager =
(SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView =
(SearchView) menu.findItem(R.id.search).getActionView();

searchView.setSearchableInfo(
searchManager.getSearchableInfo(getComponentName()));

return true;
}


And my manifest.xml



<activity
android:name=".Activities.MainActivity"
android:label="@string/addWordLabel_Act"
android:launchMode="singleTop"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.SEARCH"/>
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>


Finally, here you have some screenshots of the problem:
SearchView before tapping



SearchView after first tap, Here's the problem



SearchView after second tap, "the normal SearchView"



And that's all.



Note: I haven't implemented an Activity/Fragment to handle the Search yet.










share|improve this question





























    0















    I've implemented SearchView inside my toolbar, following Android's official instructions.



    SearchView works well itself, but when I tap the search icon, it is shifted to the left instead of showing the Search Hint and Close button, although if I click this "second Search" icon, finally I get the typical search view.



    Here is my xml of the toolbar:



    <item android:id="@+id/search"
    android:title="@string/search_view"
    app:showAsAction="collapseActionView|ifRoom"
    android:iconTint="@android:color/white"
    android:icon="@drawable/ic_search_white_24dp"
    app:actionViewClass="android.widget.SearchView" />


    And my onCreateOptionsMenu



    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.options_menu, menu);

    // Associate searchable configuration with the SearchView
    SearchManager searchManager =
    (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView =
    (SearchView) menu.findItem(R.id.search).getActionView();

    searchView.setSearchableInfo(
    searchManager.getSearchableInfo(getComponentName()));

    return true;
    }


    And my manifest.xml



    <activity
    android:name=".Activities.MainActivity"
    android:label="@string/addWordLabel_Act"
    android:launchMode="singleTop"
    android:screenOrientation="portrait">
    <intent-filter>
    <action android:name="android.intent.action.SEARCH"/>
    </intent-filter>
    <meta-data
    android:name="android.app.searchable"
    android:resource="@xml/searchable" />
    </activity>


    Finally, here you have some screenshots of the problem:
    SearchView before tapping



    SearchView after first tap, Here's the problem



    SearchView after second tap, "the normal SearchView"



    And that's all.



    Note: I haven't implemented an Activity/Fragment to handle the Search yet.










    share|improve this question



























      0












      0








      0








      I've implemented SearchView inside my toolbar, following Android's official instructions.



      SearchView works well itself, but when I tap the search icon, it is shifted to the left instead of showing the Search Hint and Close button, although if I click this "second Search" icon, finally I get the typical search view.



      Here is my xml of the toolbar:



      <item android:id="@+id/search"
      android:title="@string/search_view"
      app:showAsAction="collapseActionView|ifRoom"
      android:iconTint="@android:color/white"
      android:icon="@drawable/ic_search_white_24dp"
      app:actionViewClass="android.widget.SearchView" />


      And my onCreateOptionsMenu



      @Override
      public boolean onCreateOptionsMenu(Menu menu) {

      MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.menu.options_menu, menu);

      // Associate searchable configuration with the SearchView
      SearchManager searchManager =
      (SearchManager) getSystemService(Context.SEARCH_SERVICE);
      SearchView searchView =
      (SearchView) menu.findItem(R.id.search).getActionView();

      searchView.setSearchableInfo(
      searchManager.getSearchableInfo(getComponentName()));

      return true;
      }


      And my manifest.xml



      <activity
      android:name=".Activities.MainActivity"
      android:label="@string/addWordLabel_Act"
      android:launchMode="singleTop"
      android:screenOrientation="portrait">
      <intent-filter>
      <action android:name="android.intent.action.SEARCH"/>
      </intent-filter>
      <meta-data
      android:name="android.app.searchable"
      android:resource="@xml/searchable" />
      </activity>


      Finally, here you have some screenshots of the problem:
      SearchView before tapping



      SearchView after first tap, Here's the problem



      SearchView after second tap, "the normal SearchView"



      And that's all.



      Note: I haven't implemented an Activity/Fragment to handle the Search yet.










      share|improve this question
















      I've implemented SearchView inside my toolbar, following Android's official instructions.



      SearchView works well itself, but when I tap the search icon, it is shifted to the left instead of showing the Search Hint and Close button, although if I click this "second Search" icon, finally I get the typical search view.



      Here is my xml of the toolbar:



      <item android:id="@+id/search"
      android:title="@string/search_view"
      app:showAsAction="collapseActionView|ifRoom"
      android:iconTint="@android:color/white"
      android:icon="@drawable/ic_search_white_24dp"
      app:actionViewClass="android.widget.SearchView" />


      And my onCreateOptionsMenu



      @Override
      public boolean onCreateOptionsMenu(Menu menu) {

      MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.menu.options_menu, menu);

      // Associate searchable configuration with the SearchView
      SearchManager searchManager =
      (SearchManager) getSystemService(Context.SEARCH_SERVICE);
      SearchView searchView =
      (SearchView) menu.findItem(R.id.search).getActionView();

      searchView.setSearchableInfo(
      searchManager.getSearchableInfo(getComponentName()));

      return true;
      }


      And my manifest.xml



      <activity
      android:name=".Activities.MainActivity"
      android:label="@string/addWordLabel_Act"
      android:launchMode="singleTop"
      android:screenOrientation="portrait">
      <intent-filter>
      <action android:name="android.intent.action.SEARCH"/>
      </intent-filter>
      <meta-data
      android:name="android.app.searchable"
      android:resource="@xml/searchable" />
      </activity>


      Finally, here you have some screenshots of the problem:
      SearchView before tapping



      SearchView after first tap, Here's the problem



      SearchView after second tap, "the normal SearchView"



      And that's all.



      Note: I haven't implemented an Activity/Fragment to handle the Search yet.







      java android toolbar searchview






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 31 '18 at 16:34









      Cœur

      18.1k9108148




      18.1k9108148










      asked Oct 20 '18 at 22:44









      VentoVento

      63




      63
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Finally, I got the solution. It was easy, but I've spent two days trying to figure it out.



          Just, for compatibility issues, use



          app:actionViewClass="android.support.v7.widget.SearchView"


          instead of app:actionViewClass="android.widget.SearchView"



          and, of course, change



          SearchManager searchManager =
          (SearchManager) getSystemService(Context.SEARCH_SERVICE);
          SearchView searchView =
          (SearchView) menu.findItem(R.id.search).getActionView();


          by



          SearchManager searchManager =
          (SearchManager) getSystemService(Context.SEARCH_SERVICE);
          android.support.v7.widget.SearchView searchView =
          (android.support.v7.widget.SearchView) menu.findItem(R.id.search).getActionView();





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52910700%2fsearchview-icon-shows-twice%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Finally, I got the solution. It was easy, but I've spent two days trying to figure it out.



            Just, for compatibility issues, use



            app:actionViewClass="android.support.v7.widget.SearchView"


            instead of app:actionViewClass="android.widget.SearchView"



            and, of course, change



            SearchManager searchManager =
            (SearchManager) getSystemService(Context.SEARCH_SERVICE);
            SearchView searchView =
            (SearchView) menu.findItem(R.id.search).getActionView();


            by



            SearchManager searchManager =
            (SearchManager) getSystemService(Context.SEARCH_SERVICE);
            android.support.v7.widget.SearchView searchView =
            (android.support.v7.widget.SearchView) menu.findItem(R.id.search).getActionView();





            share|improve this answer




























              0














              Finally, I got the solution. It was easy, but I've spent two days trying to figure it out.



              Just, for compatibility issues, use



              app:actionViewClass="android.support.v7.widget.SearchView"


              instead of app:actionViewClass="android.widget.SearchView"



              and, of course, change



              SearchManager searchManager =
              (SearchManager) getSystemService(Context.SEARCH_SERVICE);
              SearchView searchView =
              (SearchView) menu.findItem(R.id.search).getActionView();


              by



              SearchManager searchManager =
              (SearchManager) getSystemService(Context.SEARCH_SERVICE);
              android.support.v7.widget.SearchView searchView =
              (android.support.v7.widget.SearchView) menu.findItem(R.id.search).getActionView();





              share|improve this answer


























                0












                0








                0







                Finally, I got the solution. It was easy, but I've spent two days trying to figure it out.



                Just, for compatibility issues, use



                app:actionViewClass="android.support.v7.widget.SearchView"


                instead of app:actionViewClass="android.widget.SearchView"



                and, of course, change



                SearchManager searchManager =
                (SearchManager) getSystemService(Context.SEARCH_SERVICE);
                SearchView searchView =
                (SearchView) menu.findItem(R.id.search).getActionView();


                by



                SearchManager searchManager =
                (SearchManager) getSystemService(Context.SEARCH_SERVICE);
                android.support.v7.widget.SearchView searchView =
                (android.support.v7.widget.SearchView) menu.findItem(R.id.search).getActionView();





                share|improve this answer













                Finally, I got the solution. It was easy, but I've spent two days trying to figure it out.



                Just, for compatibility issues, use



                app:actionViewClass="android.support.v7.widget.SearchView"


                instead of app:actionViewClass="android.widget.SearchView"



                and, of course, change



                SearchManager searchManager =
                (SearchManager) getSystemService(Context.SEARCH_SERVICE);
                SearchView searchView =
                (SearchView) menu.findItem(R.id.search).getActionView();


                by



                SearchManager searchManager =
                (SearchManager) getSystemService(Context.SEARCH_SERVICE);
                android.support.v7.widget.SearchView searchView =
                (android.support.v7.widget.SearchView) menu.findItem(R.id.search).getActionView();






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Oct 20 '18 at 23:24









                VentoVento

                63




                63
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52910700%2fsearchview-icon-shows-twice%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Mossoró

                    Error while reading .h5 file using the rhdf5 package in R

                    Pushsharp Apns notification error: 'InvalidToken'