Hi Android folks,

We currently want to customize the default Android search dialog UI to
have our own look&feel. After looking into Android source code, we
found out that two things of Android preventing us from doing it.

1. SearchManager declares an instance of SearchDialog as one of its
private fields
2. SearchDialog is not compiled into the SDK. We are using 1.0R2.

As for problem 1, we actually could work it around by reflection. The
following is our code snippet to expose the private search dialog
field of SearchManager

                                SearchManager searchManager =
(SearchManager)getSystemService(Context.SEARCH_SERVICE);

                                try
                                {
                                        Class<?> searchManagerClass =
searchManager.getClass();
                                        Field searchDialogField =
searchManagerClass.getDeclaredField("mSearchDialog");
                                        searchDialogField.setAccessible
(true);
                                        searchDialogField.set
(searchManager, new OurCustomSearchDialog(context));
                                } catch (SecurityException e)
                                {
                                        // TODO Auto-generated catch
block
                                        e.printStackTrace();
                                } catch (NoSuchFieldException e)
                                {
                                        // TODO Auto-generated catch
block
                                        e.printStackTrace();
                                } catch (IllegalArgumentException e)
                                {
                                        // TODO Auto-generated catch
block
                                        e.printStackTrace();
                                } catch (IllegalAccessException e)
                                {
                                        // TODO Auto-generated catch
block
                                        e.printStackTrace();
                                }
However, when the code comes to the line

searchDialogField.set(searchManager, new OurCustomSearchDialog
(context));,

it brings up the second problem. Because SearchDialog is not in the
SDK, we have no way to create our custom search dialog by subclassing
it. Then the line is actually not possible.

Since the approach above cannot achieve our goal, I wonder if any of
you guys happen to know how to customize the default Android search
dialog, or at least why Google takes measures like that to protect
SearchDialog from being customized. Thanks!

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to