getColor(Int Id)在Android6.0 Marshmlow上被废弃(API 23)

getColor(Int Id)在Android6.0 Marshmlow上被废弃(API 23)

这个Resources.getColor(int id)方法已被废弃。

@ColorInt@Deprecatedpublic int getColor(@ColorRes int id) throws NotFoundException {
    return getColor(id, null);}

我该怎么办?


肥皂起泡泡
浏览 690回答 3
3回答

翻过高山走不出你

我不想只为了getColor所以我用的是public&nbsp;static&nbsp;int&nbsp;getColorWrapper(Context&nbsp;context,&nbsp;int&nbsp;id)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(Build.VERSION.SDK_INT&nbsp;>=&nbsp;Build.VERSION_CODES.M)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;context.getColor(id); &nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//noinspection&nbsp;deprecation &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;context.getResources().getColor(id); &nbsp;&nbsp;&nbsp;&nbsp;}}我想这段代码应该运行得很好,并且不推荐。getColor不能从API<23中消失。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Android