Add search icon on action bar android -


good days guys.

i have search icon in action bar image below

enter image description here

when clicked, want action bar change edittext , has search icon beside edittext

i know how make edittext image, how put edittext on action bar image below ? , want make data display value once edittext has filled value. should use intent ?

enter image description here

this i've tried far.

activity a

 getdata(devicename, month); // retrieve data `mysql` , load listview          @override          public boolean oncreateoptionsmenu(menu menu) {             // inflate menu; adds items action bar if present.             menuinflater inflater = getmenuinflater();             inflater.inflate(r.menu.create_menu, menu);              return true;         }          @override         public boolean onprepareoptionsmenu(menu menu) {             msearchaction = menu.finditem(r.id.search);             return super.onprepareoptionsmenu(menu);         }          @override         public boolean onoptionsitemselected(menuitem item) {             // handle action bar item clicks here. action bar             // automatically handle clicks on home/up button, long             // specify parent activity in androidmanifest.xml.             switch (item.getitemid()) {                  case r.id.search: // should need add intent ?                     handlemenusearch();                     return true;                  case r.id.add: // create new file                     view menuitemview = findviewbyid(r.id.add);                     popupmenu po = new popupmenu(homepage.this, menuitemview); //for drop-down menu                     po.getmenuinflater().inflate(r.menu.popup_menu, po.getmenu());                     po.setonmenuitemclicklistener(new popupmenu.onmenuitemclicklistener() {                         public boolean onmenuitemclick(menuitem item) {                             //  toast.maketext(mainactivity.this, "you clicked : " + item.gettitle(), toast.length_short).show();                             if ("create new file".equals(item.gettitle())) {                                 intent intent = new intent(homepage.this, information.class);  // go information class                                 startactivity(intent);                              } else if ("edit file".equals(item.gettitle())) {                                 intent intent = new intent(homepage.this, edit.class);                                 startactivity(intent);                             }                             return true;                         }                     });                     po.show(); //showing popup menu              }             return super.onoptionsitemselected(item);         }          protected void handlemenusearch(){             actionbar action = getsupportactionbar(); //get actionbar              if(issearchopened){ //test if search open                  action.setdisplayshowcustomenabled(false); //disable custom view inside actionbar                 action.setdisplayshowtitleenabled(true); //show title in action bar                  //hides keyboard                 inputmethodmanager imm = (inputmethodmanager) getsystemservice(context.input_method_service);                 imm.hidesoftinputfromwindow(edtseach.getwindowtoken(), 0);                  //add search icon in action bar                 msearchaction.seticon(getresources().getdrawable(r.mipmap.search));                  issearchopened = false;             } else { //open search entry                  action.setdisplayshowcustomenabled(true); //enable display                 // custom view in action bar.                 action.setcustomview(r.layout.search_bar);//add custom view                 action.setdisplayshowtitleenabled(false); //hide title                  edtseach = (edittext)action.getcustomview().findviewbyid(r.id.edtsearch); //the text editor                  //this listener search when user clicks on search button                 edtseach.setoneditoractionlistener(new textview.oneditoractionlistener() {                     @override                     public boolean oneditoraction(textview v, int actionid, keyevent event) {                         if (actionid == editorinfo.ime_action_search) {                             dosearch();                             return true;                         }                         return false;                     }                 });                   edtseach.requestfocus();                  //open keyboard focused in edtsearch                 inputmethodmanager imm = (inputmethodmanager) getsystemservice(context.input_method_service);                 imm.showsoftinput(edtseach, inputmethodmanager.show_implicit);                   //add close icon                 msearchaction.seticon(getresources().getdrawable(r.mipmap.search));                  issearchopened = true;             }         }        @override         public void onbackpressed() {             if(issearchopened) {                 handlemenusearch();                 return;             }             super.onbackpressed();         }          private void dosearch() {     //         }       } 

screen shot of activity a

enter image description here

when search icon pressed, supposed intent page , have search icon on edittext (exactly second image), didn't. remains in same page.

enter image description here

this want (from wechat)

before icon pressed

enter image description here

after pressed

enter image description here

that widget name is: android.support.v7.widget.searchview

http://developer.android.com/reference/android/widget/searchview.html

in menu:

 <item         android:id="@+id/action_search"         android:icon="@drawable/abc_ic_search_api_mtrl_alpha"         android:title="@string/srch"         app:actionviewclass="android.support.v7.widget.searchview"         app:showasaction="ifroom|collapseactionview" /> 

java:

 @override     public boolean oncreateoptionsmenu(menu menu) {         getmenuinflater().inflate(r.menu.menu_main, menu);         // retrieve searchview , plug searchmanager         final searchview searchview = (searchview) menuitemcompat.getactionview(menu.finditem(r.id.action_search));         searchmanager searchmanager = (searchmanager) getsystemservice(search_service);         searchview.setsearchableinfo(searchmanager.getsearchableinfo(getcomponentname()));          return true;     } 

this materialdesign icon.

android:icon="@drawable/abc_ic_search_api_mtrl_alpha" 

Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -