CompatUtils.java 文件源码

java
阅读 35 收藏 0 点赞 0 评论 0

项目:microMathematics 作者:
/**
 * Procedure sets the background for given view as a drawable with given resource id
 */
@SuppressWarnings("deprecation")
public static void updateBackground(Context c, View v, @DrawableRes int drawableId)
{
    Drawable bg = null;

    if (drawableId >= 0)
    {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        {
            bg = c.getResources().getDrawable(drawableId, c.getTheme());
        }
        else
        {
            bg = c.getResources().getDrawable(drawableId);
        }
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
    {
        v.setBackground(bg);
    }
    else
    {
        v.setBackgroundDrawable(bg);
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号