سؤال

I want to open the search (Default Search), which stays on the desktop (the google search) by clicking a button.

Here is the Xml code:

 <ImageButton 
     android:id="@+id/btnSearch" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/ic_action_search" android:text="" 
 /> 

which I used to create the button. It's a very simple button. Now I used this onclicklistener to catch the click event of that button :

imgSearch.setOnClickListener(
    new View.OnClickListener() { 
        @Override public void onClick(View v) { 
            onSearchRequested(); 
        } 
    }
); 

But couldn't find out how to exactly make it work. Please Let me know what to do.

هل كانت مفيدة؟

المحلول

You can use the Intent class with web search action:

private void onSearchRequested() { 

    Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
    intent.putExtra(SearchManager.QUERY, "your search query");
    startActivity(intent);

}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top