ImageButton中的透明背景具有涟漪效应?

Con*_*use 20 java xml android imagebutton

我想以编程方式删除ImageButton中的灰色背景.我试过很多方法来删除它 - 如 -

imageButton.setBackgroundDrawable(null);
Run Code Online (Sandbox Code Playgroud)

但是在实现它们时,我没有在触摸时对ImageButton产生连锁反应.(触摸时不突出显示).

有没有办法删除背景但保留涟漪效果或突出显示.

Moh*_*had 37

如果android:background="?attr/selectableItemBackground"这有效,我相信这个答案可以解决你的问题:

/sf/answers/1966121041/

  • 甚至更好,```android:background ="?attr/selectableItemBackgroundBorderless"``` (8认同)

小智 9

创建自己的RippleDrawable,如果要使用透明背景,则需要为Ripple使用蒙版.

 <!-- A red ripple masked against an opaque rectangle. --/>
 <ripple android:color="#ffff0000">
   <item android:id="@android:id/mask"
         android:drawable="@android:color/white" />
 </ripple>
Run Code Online (Sandbox Code Playgroud)