1

As soon as my app launches, an AsyncTask retrieves a JSON. While it's being downloaded, I show a progress dialog as usual:

protected void onPreExecute() {
    Context c = ((EventoMainActivity)mCallback);
    mDialog = new ProgressDialog(c, R.style.my_Dialog);
    mDialog.setTitle("Descargando datos del evento ");
    mDialog.setMessage("Espere un instante...");
    mDialog.setIndeterminate(true);
    mDialog.show();
}

As I want to customize the dialog, I pass my style with the constructor to change colors, etc, achieving the following result:

enter image description here

(Some styles come from inheritance from Widget.Sherlock.Light.ProgressBar)

So far so good. With the color text property I changed it to red, but that's all I managed to do. The problem is that I want to give style to the title text, to the message text, and that blue colored line.

My approach was looking for the structure of this elements in the android source (their layout xml files). I found out that the progressDialog comes from the alertDialog. And there I found the structure that defines the title parameter and the message parameter:

From alert_dialog.xml
...
<com.android.internal.widget.DialogTitle android:id="@+id/alertTitle"
                style="?android:attr/textAppearanceLarge"
                android:singleLine="true"
                android:ellipsize="end"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
...

From progress_dialog.xml
...    
<TextView android:id="@+id/message"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical" />
...

The problem is that android.R.id does not contain references to those IDs so I'm unable to reach this views in code with findByID and apply to them the style I wish.

I know how to do a custom layout but I wonder if there's some way to style the default components.

Thanks

hasanghaforian
  • 13,858
  • 11
  • 76
  • 167
Telémako
  • 673
  • 3
  • 9

2 Answers2

0

You can use the wrapper, where you can set a theme (style) to anything in the current context. You can set R.style.MyTheme as style to the alert dialog and customize that view to your own taste.

ContextThemeWrapper ctw = new ContextThemeWrapper( this, R.style.MyTheme );
AlertDialog.Builder builder= new AlertDialog.Builder( ctw );
Milos Cuculovic
  • 19,631
  • 51
  • 159
  • 265
  • I'm not using an AlertDialog, I'm using a ProgressDialog. I had already read [this](http://stackoverflow.com/a/8037099/527775) but thanks for the copypaste. – Telémako Sep 27 '12 at 15:58
0

After researching for a while I think it's not possible. The default components are styled using ids not reachable from your app which makes it not doable unless you create your own custom component.

Telémako
  • 673
  • 3
  • 9