リップルアニメーションのメモ


background

  • すべてのView(CardViewを除く)
layout
<View
    android:background="?android:attr/selectableItemBackground"/>

foreground

  • FrameLayout
  • CardView(FrameLayoutを継承しているため)
  • Android 6.0/APIレベル 23/Marshmallow以上のすべてのView
layout
<View
    android:foreground="?android:attr/selectableItemBackground"/>

コードで設定

src
val outValue = TypedValue()
getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true)
view.setBackgroundResource(outValue.resourceId)

カスタムのbackgroundにリップルアニメーションをつける

drawable/ripple.xml
<ripple xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- ここをカスタム -->
    <item android:drawable="@color/colorAccent"/>
</ripple>
layout
<View
    android:background="@drawable/ripple"/>