Skip to content

Instantly share code, notes, and snippets.

@alexzaitsev
Last active December 6, 2018 13:29
Show Gist options
  • Save alexzaitsev/b33299aa7d4230a72423bfd8cdd84509 to your computer and use it in GitHub Desktop.
Save alexzaitsev/b33299aa7d4230a72423bfd8cdd84509 to your computer and use it in GitHub Desktop.
AppBarLayout custom shadow
@JvmStatic
@BindingAdapter("isCustomShadowEnabled")
fun setAppBarDefaultShadowEnabled(appBarLayout: AppBarLayout, isCustomShadowEnabled: Boolean) {
if (isCustomShadowEnabled) {
appBarLayout.outlineProvider = null // removes the shadow below the AppBar without affecting elevation
// add the shadow
val inflater = LayoutInflater.from(appBarLayout.context)
val shadowView = inflater.inflate(R.layout.view_shadow, appBarLayout, false)
appBarLayout.addView(shadowView)
}
}
<android.support.design.widget.AppBarLayout
bind:isCustomShadowEnabled="@{true}" // add this line to your AppBarLayout
<style name="Shadow">
<item name="android:background">@color/light_gray</item>
</style>
<style name="Shadow.Horizontal">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">1dp</item>
</style>
<?xml version="1.0" encoding="utf-8"?>
<View style="@style/Shadow.Horizontal"/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment