Skip to content

Instantly share code, notes, and snippets.

@scruffyfox
Created August 16, 2018 10:28
Show Gist options
  • Save scruffyfox/d0a868056c6e2b376eb4ec2a1862bb07 to your computer and use it in GitHub Desktop.
Save scruffyfox/d0a868056c6e2b376eb4ec2a1862bb07 to your computer and use it in GitHub Desktop.
Set action and status colour
/**
* Sets the colour of the actionbar
* @param colourRes
*/
private void setActionColour(@ColorRes int colourRes, @ColorRes int colourResDark)
{
try
{
((AppCompatActivity)getActivity()).getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(colourRes)));
((AppCompatActivity)getActivity()).getSupportActionBar().setElevation(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4f, getResources().getDisplayMetrics()));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
Window window = getActivity().getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setStatusBarColor(getResources().getColor(colourResDark));
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment