Last active
September 9, 2018 15:25
-
-
Save Orange168/cae18db85d29843ad8d424250a554fac to your computer and use it in GitHub Desktop.
[获取Preference.xml中的icon] #UI #Android #Bitmap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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