android start user defined activity on search button pressed @ handset

▼魔方 西西 提交于 2020-01-09 09:58:14

问题


I am using following code to start activity when user pressing search button on the handset

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if(keyCode == KeyEvent.KEYCODE_SEARCH){
        Util.startActivity(ReviewsDetail.this, KeywordSearch.class);
        return false;
    }else{
        return super.onKeyUp(keyCode, event); 
    }
}

But here are few issues with it please look at the following image.

When press search button it first show google search box at the top of activity then start activity which i want to start

When click on the back button displays empty actiivty


回答1:


 @Override
 public boolean onSearchRequested() {

     // your logic here

     return false;  // don't go ahead and show the search box
 }



回答2:


The Search button and system's search request are both working the same when invoked from any activity of your app. If you want to override it you will have to override it for EVERY activity you want it to work from in the same way. Unfortunately, there is no way to override it "globally", neither a way to subclass/style/theme the default search popup. So sad, google.



来源:https://stackoverflow.com/questions/1912947/android-start-user-defined-activity-on-search-button-pressed-handset

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