使用colorControlHighlight与颜色或可绘制选择器的android自定义波纹

时间:2019-06-24 14:54:02

标签: android material-design android-theme ripple rippledrawable

我有两种设置波纹自定义颜色的方法:

1)

 android:background="?attr/selectableItemBackground"
    android:theme="@style/Theme.DayNight"

<item name="colorControlHighlight">@color/my_color</item>

2)

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_pressed="true">
    <shape android:shape="oval">
      <solid android:color="@color/google_grey200_alpha_10"/>
    </shape>
  </item>
  <item android:state_focused="true">
    <shape android:shape="oval">
      <solid android:color="@color/google_grey200_alpha_12"/>
    </shape>
  </item>
  <item android:state_hovered="true">
    <shape android:shape="oval">
      <solid android:color="@color/google_grey200_alpha_4"/>
    </shape>
  </item>
</selector>

并将此可绘制选择器设置为android:background

即使它没有为android:state_focusedandroid:state_hovered定义颜色,它还是更干净,更推荐的第一方法吗?

物质波纹只是忽略了这些状态?

0 个答案:

没有答案