Last active
December 6, 2018 13:29
-
-
Save alexzaitsev/b33299aa7d4230a72423bfd8cdd84509 to your computer and use it in GitHub Desktop.
AppBarLayout custom shadow
This file contains hidden or 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
@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) | |
} | |
} |
This file contains hidden or 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
<android.support.design.widget.AppBarLayout | |
bind:isCustomShadowEnabled="@{true}" // add this line to your AppBarLayout |
This file contains hidden or 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
<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> |
This file contains hidden or 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
<?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