如何在圆角布局上添加涟漪效果?

Rab*_*dka 5 android android-layout rippledrawable

我想在带圆角的布局上设置涟漪效果.我该怎么做?

Jit*_*iya 7

使用以下代码.

<?xml version="1.0" encoding="utf-8"?>
<ripple android:color="@color/COLOR_WHILE_PRESSING" xmlns:android="http://schemas.android.com/apk/res/android">
 <item android:drawable="@drawable/round_corner"></item>
</ripple>
Run Code Online (Sandbox Code Playgroud)

round_corner.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
 <solid android:color="@color/BACKGROUND_COLOR" />
 <corners android:radius="6dp" />
</shape>
Run Code Online (Sandbox Code Playgroud)


Che*_*kar -4

只需在 xml 文件中设置这些属性

android:background="?android:attr/selectableItemBackground"
android:clickable="true"
Run Code Online (Sandbox Code Playgroud)

应该可以做到这一点。

  • 这不会使布局边框角变圆。 (2认同)