设置背景信息:

RelativeLayout layout = (RelativeLayout) findViewById(R.id.background);
layout.setBackgroundResource(R.drawable.ready);

这是最好的方法吗?


当前回答

setBackground(getContext().getResources().getDrawable(R.drawable.green_rounded_frame));

其他回答

试试下面的代码:

Drawable thumb = ContextCompat.getDrawable(getActivity(), R.mipmap.cir_32);
mSeekBar.setThumb(thumb);

你也可以设置任何图片的背景:

View v;
Drawable image=(Drawable)getResources().getDrawable(R.drawable.img);
(ImageView)v.setBackground(image);
setBackground(getContext().getResources().getDrawable(R.drawable.green_rounded_frame));

如果你使用AndroidX,你应该使用:

AppCompatResources.getDrawable(context, R.drawable.your_drawable)

不推荐使用前面列出的方法。

试试ViewCompat。setBackground (yourView drawableBackground)