他们之间有什么区别?据我所见,他们都做同样的事情。
答案 0 :(得分:1)
如果您访问来源,您会发现PhoneWindow.class已实施Window.setBackgroundDrawable
方法:
@Override
public final void setBackgroundDrawable(Drawable drawable) {
if (drawable != mBackgroundDrawable || mBackgroundResource != 0) {
mBackgroundResource = 0;
mBackgroundDrawable = drawable;
if (mDecor != null) {
mDecor.setWindowBackground(drawable);
}
if (mBackgroundFallbackResource != 0) {
mDecor.setBackgroundFallback(drawable != null ? 0 : mBackgroundFallbackResource);
}
}
}
如您所见,它调用了DecorView setWindowBackground
的不同方法:
public void setWindowBackground(Drawable drawable) {
if (getBackground() != drawable) {
setBackgroundDrawable(drawable);
if (drawable != null) {
drawable.getPadding(mBackgroundPadding);
} else {
mBackgroundPadding.setEmpty();
}
drawableChanged();
}
}
实际上使用方法DecorView.setBackgroundDrawable
,但也为Window
提供了额外的逻辑。所以我建议你使用getWindow().setBackgroundDrawable()
。