I\'m trying to realize a translucent statusbar (so that my navigation-view is BEHIND the statusbar) but still like to change the color of my actionbar dynam
Actually, it's fairly easy to implement.
First step - is to change height of the Toolbar
:
height
to wrap_content
so for me it looks like this:
Then you override resources for v19
:
Then, in the Activity
, setting padding
for the Toolbar
:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setPadding(0, getStatusBarHeight(), 0, 0);
......
......
public int getStatusBarHeight() {
int result = 0;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
result = getResources().getDimensionPixelSize(resourceId);
}
}
return result;
}
And actually, it's pretty much it. Now once I want to change colour of the Toolbar, I'm calling this:
if (getSupportActionBar() != null) {
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.GREEN));
}
The activity's layout:
NB! On pre-Kitkat OS-versions, status bar remained the same, non-translucent.
I've uploaded the source code of the test-application to my dropbox - feel free to check it out.
I hope, it helps