小编Geo*_*geP的帖子

setBackgroundResource与setBackground的行为与RippleDrawable不同

我想设置RippleDrawable一个列表视图行的背景.使用时view.setBackgroundResource(R.drawable.ripple)一切正常.在尝试时

view.setBackground(view.getContext().getDrawable(R.drawable.ripple))
Run Code Online (Sandbox Code Playgroud)

它可以工作,但是当快速触摸项目时没有显示波纹(我也有项目的激活/检查状态),它只在我按下视图时出现.

View类中的setBackgroundResource方法如下所示:

if (resid != 0 && resid == mBackgroundResource) {
    return;
}

Drawable d = null;
if (resid != 0) {
    d = mContext.getDrawable(resid);
}
setBackground(d);

mBackgroundResource = resid;
Run Code Online (Sandbox Code Playgroud)

所以基本上我正在尝试手动完成的事情.

注意:我想使用setBackground方法,因为我想以编程方式创建RippleDrawable.

有没有人知道为什么会这样?

android rippledrawable

5
推荐指数
1
解决办法
549
查看次数

标签 统计

android ×1

rippledrawable ×1