Created
June 1, 2020 21:17
-
-
Save TylerMcCraw/9daf9731fef78d82eda677bfb15f9b34 to your computer and use it in GitHub Desktop.
Always show AppBarLayout elevation regardless of state
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
<?xml version="1.0" encoding="utf-8"?> | |
<!-- | |
StateListAnimator which sets elevation for all states of an AppBarLayout | |
Modified from https://github.com/material-components/material-components-android/blob/master/lib/java/com/google/android/material/appbar/res/animator-v21/design_appbar_state_list_animator.xml | |
--> | |
<selector xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto"> | |
<item | |
android:state_enabled="true" | |
app:state_liftable="true" | |
app:state_lifted="false"> | |
<objectAnimator | |
android:duration="150" | |
android:propertyName="elevation" | |
android:valueTo="@dimen/design_appbar_elevation" | |
android:valueType="floatType" /> | |
</item> | |
<item android:state_enabled="true"> | |
<objectAnimator | |
android:duration="150" | |
android:propertyName="elevation" | |
android:valueTo="@dimen/design_appbar_elevation" | |
android:valueType="floatType" /> | |
</item> | |
<item> | |
<objectAnimator | |
android:duration="0" | |
android:propertyName="elevation" | |
android:valueTo="0" | |
android:valueType="floatType" /> | |
</item> | |
</selector> |
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
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
// ... inflate layout ... | |
appBarLayout.stateListAnimator = AnimatorInflater.loadStateListAnimator(context, R.animator.appbar_always_elevated_state_list_animator) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment