My application scenario is to get the LinearLayout of the entire page to set the background. When the page has no data, add a background image to the page, setBackground() to set the background image of the page:
look at the code! ! !
//获取项目中的静态资源文件
Resources resources = getContext().getResources();
//获取项目静态文件下的图片
Drawable drawable = resources.getDrawable(R.drawable.ic_clean_history);
//历史图片存量小于0设置图片,大于0设置颜色(判断是否有数据给activty页面的进行动态设置背景)
//llHistory 为xml页面的一块布局
if (mSPHistoryImgList != null) {
if (mSPHistoryImgList.size() > 0) {
llHistory.setBackgroundColor(Color.parseColor("#f4f4f4"));
} else {
//获取资源目录,没有历史图片的时候加背景图片说明
llHistory.setBackground(drawable);
}
} else {
llHistory.setBackgroundColor(Color.parseColor("#f4f4f4"));
}
Communicate with Android to learn and add me WeChat ID: yaxin_com