@@ -258,6 +258,127 @@ public static class Builder {
258258 */
259259 private View customTitleView ;
260260
261+ /**
262+ * Obtains all relevant attributes from the current theme.
263+ */
264+ private void obtainStyledAttributes () {
265+ int themeId = themeResourceId != -1 ? themeResourceId : 0 ;
266+ obtainBackground (themeId );
267+ obtainButtonTextColor (themeId );
268+ obtainItemColor (themeId );
269+ obtainItemControlColor (themeId );
270+ obtainMessageColor (themeId );
271+ obtainTitleColor (themeId );
272+ }
273+
274+ /**
275+ * Obtains the background from a specific theme.
276+ *
277+ * @param themeId
278+ * The id of the theme, the background should be obtained from, as an {@link
279+ * Integer} value
280+ */
281+ private void obtainBackground (@ StyleRes final int themeId ) {
282+ TypedArray typedArray = getContext ().getTheme ()
283+ .obtainStyledAttributes (themeId , new int []{R .attr .materialDialogBackground });
284+ int color = typedArray .getColor (0 , -1 );
285+
286+ if (color != -1 ) {
287+ setBackgroundColor (color );
288+ } else {
289+ int resourceId = typedArray .getResourceId (0 , 0 );
290+
291+ if (resourceId != 0 ) {
292+ setBackground (resourceId );
293+ }
294+ }
295+ }
296+
297+ /**
298+ * Obtains the button text color from a specific theme.
299+ *
300+ * @param themeId
301+ * The id of the theme, the button text color should be obtained from, as an {@link
302+ * Integer} value
303+ */
304+ private void obtainButtonTextColor (@ StyleRes final int themeId ) {
305+ TypedArray typedArray = getContext ().getTheme ().obtainStyledAttributes (themeId ,
306+ new int []{R .attr .materialDialogButtonTextColor });
307+ int color = typedArray .getColor (0 , -1 );
308+
309+ if (color != -1 ) {
310+ setButtonTextColor (color );
311+ }
312+ }
313+
314+ /**
315+ * Obtains the item color from a specific theme.
316+ *
317+ * @param themeId
318+ * The id of the theme, the item color should be obtained from, as an {@link
319+ * Integer} value
320+ */
321+ private void obtainItemColor (@ StyleRes final int themeId ) {
322+ TypedArray typedArray = getContext ().getTheme ()
323+ .obtainStyledAttributes (themeId , new int []{R .attr .materialDialogItemColor });
324+ int color = typedArray .getColor (0 , -1 );
325+
326+ if (color != -1 ) {
327+ setItemColor (color );
328+ }
329+ }
330+
331+ /**
332+ * Obtains the item control color from a specific theme.
333+ *
334+ * @param themeId
335+ * The id of the theme, the item control color should be obtained from, as an {@link
336+ * Integer} value
337+ */
338+ private void obtainItemControlColor (@ StyleRes final int themeId ) {
339+ TypedArray typedArray = getContext ().getTheme ().obtainStyledAttributes (themeId ,
340+ new int []{R .attr .materialDialogItemControlColor });
341+ int color = typedArray .getColor (0 , -1 );
342+
343+ if (color != -1 ) {
344+ setItemControlColor (color );
345+ }
346+ }
347+
348+ /**
349+ * Obtains the message color from a specific theme.
350+ *
351+ * @param themeId
352+ * The id of the theme, the message color should be obtained from, as an {@link
353+ * Integer} value
354+ */
355+ private void obtainMessageColor (@ StyleRes final int themeId ) {
356+ TypedArray typedArray = getContext ().getTheme ()
357+ .obtainStyledAttributes (themeId , new int []{R .attr .materialDialogMessageColor });
358+ int color = typedArray .getColor (0 , -1 );
359+
360+ if (color != -1 ) {
361+ setMessageColor (color );
362+ }
363+ }
364+
365+ /**
366+ * Obtains the title color from a specific theme.
367+ *
368+ * @param themeId
369+ * The id of the theme, the title color should be obtained from, as an {@link
370+ * Integer} value
371+ */
372+ private void obtainTitleColor (@ StyleRes final int themeId ) {
373+ TypedArray typedArray = getContext ().getTheme ()
374+ .obtainStyledAttributes (themeId , new int []{R .attr .materialDialogTitleColor });
375+ int color = typedArray .getColor (0 , -1 );
376+
377+ if (color != -1 ) {
378+ setTitleColor (color );
379+ }
380+ }
381+
261382 /**
262383 * Inflates the dialog's layout.
263384 *
@@ -710,6 +831,7 @@ public Builder(@NonNull final Context context) {
710831 this .context = context ;
711832 this .themeResourceId = -1 ;
712833 this .validators = new LinkedHashSet <>();
834+ obtainStyledAttributes ();
713835 }
714836
715837 /**
@@ -727,6 +849,7 @@ public Builder(@NonNull final Context context, @StyleRes final int themeResource
727849 this .context = context ;
728850 this .themeResourceId = themeResourceId ;
729851 this .validators = new LinkedHashSet <>();
852+ obtainStyledAttributes ();
730853 }
731854
732855 /**
0 commit comments