Created
August 16, 2018 10:28
-
-
Save scruffyfox/d0a868056c6e2b376eb4ec2a1862bb07 to your computer and use it in GitHub Desktop.
Set action and status colour
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
/** | |
* 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