Hello Marty,

Unfortunately, the search dialog was not designed to be extended in
this way.  This was not meant to "protect" it so much as a consequence
of the data-driven design of the Search system.

If you can describe some of the changes you have in mind, perhaps we
can assist with some good suggestions.

*Please* don't try to hack into it via reflection.  We cannot
guarantee compatibility across multiple phone software versions.

Andy Stadler (Google)


On Mon, Feb 9, 2009 at 7:07 PM, Marty Wang <[email protected]> wrote:
>
> 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