vendredi 29 avril 2016

How to add search and checkbox icon with their functions in android action bar?

I want to add a searchview and checkbox into action bar menu. And this checkbox will be visible if searchview is opened. And in it's opposite case it will be hidden. How I can do this? I do something below . But it doesnt work correctly. I want hide checkbox (In my notes) when searchview is closed. menu.xml

 <?xml version="1.0" encoding="utf-8"?>
    <menu xmlns:android="http://ift.tt/nIICcg"
        xmlns:app="http://ift.tt/GEGVYd">

        <item
            android:id="@+id/search_button"
            android:icon="@drawable/ic_icon_search"
            android:title="Arama"
            app:showAsAction="ifRoom|collapseActionView"

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

        </item>
        <item
            android:id="@+id/search_in_my_notes_checkbox"
            app:showAsAction="ifRoom"
            android:title="@string/search_in_my_notes"
            android:checkable="true"
            android:visible="false"

            />
    </menu>

HomeActivity.java

 public boolean onOptionsItemSelected(MenuItem item) {
        if(item.getItemId() == R.id.search_button){
            MenuItem searchInMyNotesCheckbox = (MenuItem)menu.findItem(R.id.search_in_my_notes_checkbox);
            searchInMyNotesCheckbox.setVisible(true);
        }


        return super.onOptionsItemSelected(item);
    }

enter image description here




Aucun commentaire:

Enregistrer un commentaire