Skip to content

Instantly share code, notes, and snippets.

@Orange168
Last active September 9, 2018 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Orange168/cae18db85d29843ad8d424250a554fac to your computer and use it in GitHub Desktop.
Save Orange168/cae18db85d29843ad8d424250a554fac to your computer and use it in GitHub Desktop.
[获取Preference.xml中的icon] #UI #Android #Bitmap
final Drawable icon = mPreference.getDialogIcon();
if (icon == null || icon instanceof BitmapDrawable) {
mDialogIcon = (BitmapDrawable) icon;
} else {
final Bitmap bitmap = Bitmap.createBitmap(icon.getIntrinsicWidth(),
icon.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(bitmap);
icon.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
icon.draw(canvas);
mDialogIcon = new BitmapDrawable(getResources(), bitmap);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment