设置背景信息:

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

这是最好的方法吗?


当前回答

试试ViewCompat。setBackground (yourView drawableBackground)

其他回答

if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN)
     layout.setBackgroundDrawable(getResources().getDrawable(R.drawable.ready));
else if(android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1)
     layout.setBackground(getResources().getDrawable(R.drawable.ready));
else
     layout.setBackground(ContextCompat.getDrawable(this, R.drawable.ready));

试试下面的代码:

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

如果您的背景现在在drawable文件夹中,请尝试将图像从drawable文件夹移动到项目中的drawable-nodpi文件夹。这为我工作,似乎其他图像是由他们自己重新缩放。

试试这个:

layout.setBackground(ContextCompat.getDrawable(context, R.drawable.ready));

对于API 16<:

layout.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.ready));

试试ViewCompat。setBackground (yourView drawableBackground)