在搜索按钮$ P $的Andr​​oid入门用户定义的活动pssed @手机按钮、入门、定义、用户

2023-09-13 00:19:56 作者:追忆昔年

我使用下面的code,开始活动时,对手机用户pressing搜索按钮

  @覆盖
公共布尔的onkeyup(INT键code,KeyEvent的事件){
    如果(键code == KeyEvent.KEY code_SEARCH){
        Util.startActivity(ReviewsDetail.this,KeywordSearch.class);
        返回false;
    }其他{
        返回super.onKeyUp(键code,事件);
    }
}
 

但这里有与它的几个问题,请看看下面的图片。

在preSS搜索按钮,它在活动的前首秀谷歌搜索框,然后开始活动,我想开始

在单击后退按钮显示空actiivty

解决方案

  @覆盖
 公共布尔onSearchRequested(){

     //此处是您的逻辑

     返回false; //不继续前进,显示搜索框
 }
 

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

解决方案

 @Override
 public boolean onSearchRequested() {

     // your logic here

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