Skip to content

Commit 576e1df

Browse files
committed
Implement resolving of icon attributes to resIds in AlertController
Platform code using AlertController directly currently has no way to set the correct theme-specific dialog icon in a generic way. This adds code to handle such usage. Change-Id: I48beafa1183e4edf6d5378b3985a7f9be5fcda8b
1 parent bfe1ab8 commit 576e1df

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

core/java/com/android/internal/app/AlertController.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,18 @@ public void setIcon(Drawable icon) {
347347
}
348348
}
349349

350+
/**
351+
* @param attrId the attributeId of the theme-specific drawable
352+
* to resolve the resourceId for.
353+
*
354+
* @return resId the resourceId of the theme-specific drawable
355+
*/
356+
public int getIconAttributeResId(int attrId) {
357+
TypedValue out = new TypedValue();
358+
mContext.getTheme().resolveAttribute(attrId, out, true);
359+
return out.resourceId;
360+
}
361+
350362
public void setInverseBackgroundForced(boolean forceInverseBackground) {
351363
mForceInverseBackground = forceInverseBackground;
352364
}
@@ -740,6 +752,7 @@ public static class AlertParams {
740752

741753
public int mIconId = 0;
742754
public Drawable mIcon;
755+
public int mIconAttrId = 0;
743756
public CharSequence mTitle;
744757
public View mCustomTitleView;
745758
public CharSequence mMessage;
@@ -806,6 +819,9 @@ public void apply(AlertController dialog) {
806819
if (mIconId >= 0) {
807820
dialog.setIcon(mIconId);
808821
}
822+
if (mIconAttrId > 0) {
823+
dialog.setIcon(dialog.getIconAttributeResId(mIconAttrId));
824+
}
809825
}
810826
if (mMessage != null) {
811827
dialog.setMessage(mMessage);

0 commit comments

Comments
 (0)