AlertDialog theme compatibility, possible user error

1,137 views
Skip to first unread message

tommytomatoe

unread,
Jun 14, 2012, 1:32:26 AM6/14/12
to actionba...@googlegroups.com
Hey there Jake and co.

First, thank you very much for this awesome library. With ABS I've been able to give my apps the awesome features of the actionbar and other features without issues on gingerbread as well as ics devices.

This issue might not be an issue at all. I remember reading a comment by you that the Theme.Sherlock.Dialog was not meant for dialogs, but I cannot find that comment with Google search.

Here is a code snippet of how I am building the alert dialog:

*******************************************
AlertDialog.Builder builder;
        try {
            builder =  new AlertDialog.Builder(getActivity(), R.style.Theme.Sherlock.Dialog);
        } catch (NoSuchMethodError e) {
            Log.e(TAG, "Older SDK, using old Builder");
            builder =  new AlertDialog.Builder(getActivity());
        }

********************************************

I am using the optional constructor for AlertDialog.Builder to call a theme of the dialog because the theme of the app itself uses Theme.Sherlock.Light.DarkActionbar as a parent, which causes the AlertDialog to be light, but I prefer the darker dialog box. Using that code, I get this wonky background: http://imgur.com/doBg8

I know that it is an error from me using the Theme.Sherlock.Dialog style. I came up with two different methods to resolve this:

1. Use the constant "AlertDialog.THEME_HOLO_DARK" instead of "R.style.Theme.Sherlock.Dialog". This actually works pretty nicely, but I would like to know how to do it using Sherlock themes.

2. Create a theme that uses Theme.Sherlock.Dialog as a parent and setting the attribute "abdroid:windowBackground" to a transparent resource. This also works ok but it makes the dialog box smaller than it should be, because it actually puts the dialog box inside of another dialog box, like if I used Theme.Sherlock.Dialog. Example from my themes.xml:

    <style name="Theme.Classic.Dialog" parent="Theme.Sherlock.Dialog">
        <item name="android:windowBackground">@drawable/bg_clear</item>
    </style>

If I haven't lost you, do you have any thoughts on a different approach? Is there an official style/theme I could use that comes with the Sherlock library?

Thank you again for your great contribution.

Tommy

Jake Wharton

unread,
Jun 14, 2012, 1:35:46 AM6/14/12
to actionba...@googlegroups.com
There is not, and you are correct that the theme is not for dialogs. It is for theming activities to look like dialogs.

Making an AlertDialog look like it does on ICS is much more involved than a theme can accomplish which makes it fall out of scope for ActionBarSherlock. Despite backporting the action bar which looks Holo, ABS is not meant to be a Holo backport by any means. The use of this theme is merely to put both ICS and pre-ICS on the same level visually so that customizations across the platforms will always look the same.

There is an attempt to backport the AlertDialog in the HoloEverywhere library (which I hesitate to recommend) but it too falls a bit short in achieving a full backport of the look. You may be better off just rolling a custom dialog yourself and making it look Holo-ish.

---
Jake Wharton
http://about.me/jakewharton

tommytomatoe

unread,
Jun 14, 2012, 1:48:34 AM6/14/12
to actionba...@googlegroups.com
Oh wow you are fast.

Thanks for the quick and thorough response. I was afraid of that, but not a major issue. Further down the road I might create a custom dialog layout when most of the app is written. For now I am happy using the AlertDialog.THEME_HOLO_DIALOG for ICS devices and just the stock AlertDialog on older devices.

An offtopic question. If you want I can create a new topic. Have you thought about, or have already implemented, an indeterminant horizontal progressbar above the ActionBar? To be clear I don't mean the circle but the loading bar that Google uses in the Play store before an app downloads and other areas. I am using these methods in an Asynctask to display the download progress, but it would be nice to have the indeterminant loading bar while the app tries to connect.

           @Override
        protected void onPreExecute() {
            super.onPreExecute();
            updateMenu(mMenuDownload);
            setSupportProgressBarVisibility(true);
            setSupportProgressBarIndeterminateVisibility(false);
           
        }

       //snip snip

       protected void onProgressUpdate(String... progress) {
            Log.d(TAG,progress[0]);
            setSupportProgress(100 * Integer.parseInt(progress[0]));
            btnCheckUpdate.setText("Dowloaded " + progress[0] + "/100");
       }

Thank you again for your time.


On Thursday, June 14, 2012 1:35:46 AM UTC-4, Jake Wharton wrote:
There is not, and you are correct that the theme is not for dialogs. It is for theming activities to look like dialogs.

Making an AlertDialog look like it does on ICS is much more involved than a theme can accomplish which makes it fall out of scope for ActionBarSherlock. Despite backporting the action bar which looks Holo, ABS is not meant to be a Holo backport by any means. The use of this theme is merely to put both ICS and pre-ICS on the same level visually so that customizations across the platforms will always look the same.

There is an attempt to backport the AlertDialog in the HoloEverywhere library (which I hesitate to recommend) but it too falls a bit short in achieving a full backport of the look. You may be better off just rolling a custom dialog yourself and making it look Holo-ish.

---
Jake Wharton
http://about.me/jakewharton


Jake Wharton

unread,
Jun 14, 2012, 1:50:18 AM6/14/12
to actionba...@googlegroups.com

gowtham....@photoninfotech.net

unread,
Feb 20, 2013, 12:38:35 AM2/20/13
to actionba...@googlegroups.com
hi Jake,
           I have a doubt
           1) Is it possible to override the sherlock themes for alert dialogs and progress bar to display the it in device theme i.e) Halo
Reply all
Reply to author
Forward
0 new messages