今天遇到了给ImageButton设置点击波纹效果的无效的问题,网上查了查,好像是由于背景原因
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:id="@+id/music_action_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="?selectableItemBackgroundBorderless"
app:srcCompat="@drawable/ic_play_white_40dp" />
</RelativeLayout>
于是给父控件增加了个背景,变Okay了
<!-- 背景设为透明也不影响别的显示 -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent">
<ImageButton
android:id="@+id/music_action_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="?selectableItemBackgroundBorderless"
app:srcCompat="@drawable/ic_play_white_40dp" />
</RelativeLayout>