I updated my android app to the new material design, but I also wanted to add some shadow or elevation to the Toolbar. There seem to be some (hacky) ways of doing it via ima
I have a CollapsingToolbarLayout
with Toolbar
and a Toolbar-like View
that moves up and down, but lays above NestedScrollView
, like in https://github.com/k0shk0sh/CoordinatorLayoutExample.
I tried many variants. Sometimes a shadow scrolled above a screen with NestedScrollView, sometimes the Toolbar drew a solid shadow without transparency, sometimes the shadow was aliased. Anyway, this is my solution.
Say, you have a layout:
Add a shadow (drawable/shadow.xml):
Add this method. Here scrollShadow is a view named "scroll_shadow":
private void setShadowVisibility(int visibility) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
scrollShadow.setVisibility(visibility);
}
}
Manipulate it as you wish. It will show a gradient on pre-Lollipop devices and shows a normal shadow for Android 5.0+.