Simply put this code into the onCreate
method of your target activity:
int color = getResources().getColor(R.color.your_top_bar_color);
setTaskDescription(new ActivityManager.TaskDescription(null, null, color));
Please be aware that the code above requires API level 21 (Android 5.0 Lolipop) or higher. In case you need to support older devices as well, you can surround the code with following condition:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
int color = getResources().getColor(R.color.your_top_bar_color);
setTaskDescription(new ActivityManager.TaskDescription(null, null, color));
}
Also be aware that you will need to set the colour of top bar in every activity, otherwise your color will be reset when launching another activity. (You can ease this problem by putting the code into some kind of BaseActivity, from which other Activities will inherit.)
Helpful article about this topic: https://www.bignerdranch.com/blog/polishing-your-Android-overview-screen-entry/