Is there anyway to capture when the user clicks on the application icon in the built in search dialog? Please note I am NOT referring to a custom dialog but to android built in search dialog.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Nope, there is no way to make the
SearchDialog‘s app icon clickable.But just for fun, let’s assume there existed some hacky workaround that would get the job done. Cool, we have got the desired behavior… but now we have two issues:
The behavior of the
SearchDialogis not consistent with other Android devices. This lessens the user experience since users expect search interfaces to work the same on all Android devices.Your app now makes use of the internal APIs, which may or may not remain consistent when new SDKs are released. For all you know, the Android team could change the app icon’s
idfrom@+id/search_app_iconto@+id/search_home_icon. Your hack depends on the internal APIs… so such a change will cause newer devices running your app to crash (as any runtime search forsearch_app_iconwill returnnull).Further, companies like Samsung and HTC are free to alter the internal APIs before they release their new devices to the public. The next Samsung Galaxy could potentially completely re-implement the
SearchDialogclass, update its UI/theme, etc… you can never know for sure.So basically, you can’t… and you shouldn’t make an attempt to do so.
Just because I’m bored, here’s the source code that led me to my answer:
Check out the source code for
SearchManager.java, and notice that theSearchManagerkeeps theSearchDialogas a private instance variablemSearchDialog.Check out the source code for
SearchDialog.java, and notice that theSearchDialogreferences the app icon as the private instance variablemAppIcon. Also notice that theSearchDialoginitializes the variable through a call tofindViewById, as seen here.Check out the source code for
search_bar.xmland notice that theImageViewis not set toclickableby default. Since there are no (methods in the public SDK that alter the behavior of thisView, there is no reliable way to make it clickable.