Last active
March 16, 2016 18:59
-
-
Save Sammiches327/edc37b3653275a23bb23 to your computer and use it in GitHub Desktop.
Exemplifies changing the recent apps overview color on Lollipop+ devices.
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
1. The text color changes from white to black depending on the color you choose. This isn't controllable. | |
2. Method params: this.setTaskDescription(new ActivityManager.TaskDescription(String label, Bitmap resource, int Color)); |
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
public class SampleActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
//Backward compatibilty; ignored on anything lower than Lollipop | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
this.setTaskDescription(new ActivityManager.TaskDescription("App Name", // Name | |
drawableToBitmap(getResources().getDrawable(R.mipmap.ic_launcher, null)), // Icon | |
Color.parseColor("#ffffff"))); // Color; this is what you were asking about. | |
} | |
} | |
/** | |
* Converts a drawable resource into a bitmap | |
* | |
* @param drawable | |
* @return Bitmap | |
*/ | |
public static Bitmap drawableToBitmap(Drawable drawable) { | |
if (drawable instanceof BitmapDrawable) { | |
return ((BitmapDrawable) drawable).getBitmap(); | |
} | |
// We ask for the bounds if they have been set as they would be most | |
// correct, then we check we are > 0 | |
final int width = !drawable.getBounds().isEmpty() ? | |
drawable.getBounds().width() : drawable.getIntrinsicWidth(); | |
final int height = !drawable.getBounds().isEmpty() ? | |
drawable.getBounds().height() : drawable.getIntrinsicHeight(); | |
// Now we check we are > 0 | |
final Bitmap bitmap = Bitmap.createBitmap(width <= 0 ? 1 : width, height <= 0 ? 1 : height, | |
Bitmap.Config.ARGB_8888); | |
Canvas canvas = new Canvas(bitmap); | |
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); | |
drawable.draw(canvas); | |
return bitmap; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment