How can I call search dialog on button click in android?

拈花ヽ惹草 提交于 2020-01-06 08:25:12

问题


I am making a small application where I have to call search dialog on search button click please give me simple code or simple tutorial because I have seen many example but I am not so expert to call the search dialog please help me thanks in advance


回答1:


UPDATE: (since we're talking about the hardware button)

Declare a searchable configuration: http://developer.android.com/guide/topics/search/searchable-config.html. There is an example at the bottom of the linked page.

Then create a searchable activity: http://developer.android.com/guide/topics/search/search-dialog.html#SearchableActivity

And then, for any activity that should react to the search button being pressed, do this: http://developer.android.com/guide/topics/search/search-dialog.html#SearchDialog




回答2:


Override search button as :

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
        if(keyCode == KeyEvent.KEYCODE_SEARCH){
                //do, what you want
        }
}  


来源:https://stackoverflow.com/questions/6744130/how-can-i-call-search-dialog-on-button-click-in-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!