Android getResources().getDrawable() deprecated API 22

攻克Windows平台3DGS复现:从环境配置到可视化实战全记录 本文详细记录了在Windows平台成功复现3D Gaussian Splatting(3DGS)的完整流程,涵盖从环境配置、依赖安装、数据准备到模型训练与可视化的全步骤。重点解决了Windows下CUDA版本匹配、Visual Studio编译及SIBR_viewers可视化工具部署等核心难题,为开发者提供了一份详实的避坑指南与实战手册。 阅读详情

以下解决方法摘自 stackoverflow , 点击下方链接可跳转

Android getResources().getDrawable() deprecated API 22

No.1

You have some options to handle this deprecation the right (and future proof) way, depending on which kind of drawable you are loading:

  • A) drawables with theme attributes
ContextCompat.getDrawable(getActivity(), R.drawable.name);

You’ll obtain a styled Drawable as your Activity theme instructs. This is probably what you need.

* B) drawables without theme attributes

ResourcesCompat.getDrawable(getResources(), R.drawable.name, null);

You’ll get your unstyled drawable the old way.

EXTRA) drawables with theme attributes from another theme

ResourcesCompat.getDrawable(getResources(), R.drawable.name, anotherTheme);

Explanation:

API 21 (Android 5.0 Lollipop) introduced some new theme attributes such as android:colorAccent that modify the appearance of drawables that hold references to those new theme attributes values.The AppCompat library handles pre and post-Lollipop drawable styling for you.

If you do use the deprecated getDrawable() method to obtain a drawable resource with theme attributes, you will get a partially-styled drawable and a logcat warning.You can see this in API 22 android.content.res.Resources source code:

@Deprecated
@Nullable
public Drawable getDrawable(int id) throws NotFoundException {
    final Drawable d = getDrawable(id, null);
    if (d != null && d.canApplyTheme()) {
        Log.w(TAG, "Drawable " + getResourceName(id) + " has unresolved theme "
                + "attributes! Consider using Resources.getDrawable(int, Theme) or "
                + "Context.getDrawable(int).", new RuntimeException());
    }
    return d;
}

No.2

You should use the following code from the support library instead:

ContextCompat.getDrawable(context, R.drawable.***)

Using this method is equivalent to calling:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    return resources.getDrawable(id, context.getTheme());
} else {
    return resources.getDrawable(id);
}

As of API 21, you should use the getDrawable(int, Theme) method instead of getDrawable(int), as it allows you to fetch a drawable object associated with a particular resource ID for the given screen density/theme. Calling the deprecated getDrawable(int) method is equivalent to calling getDrawable(int, null).

PICO SCOPE 二次开发 基于C#开发一个简单的PICO示波器的上位机工作,与MCC600运动控制卡一起,实现数据自动采集 阅读详情

相关推荐

基于FPGA的UDP 通信(六)

本文基于FPGA和MATLAB对千兆以太网通信模块UDP数据发送(FPGA发送)进行联合调试。

记录所学,分享知识,结识挚友 4696

getDrawable(int)is deprecated as of API 22: Android 5.1 (Lollipop)

【代码】'getDrawable(int)' is deprecated as of API 22: Android 5.1 (Lollipop)

qq_27494201的博客 277

喷涂机器人系列编程:ABB IRB 5500_(2).ABB IRB 5500喷涂机器人系统架构与组件

ABB IRB 5500喷涂机器人系统不仅在性能上表现出色,而且在安全和维护方面也提供了全面的解决方案。通过本文的详细介绍,希望读者能够更好地理解和掌握这一系统的架构和功能,为实际应用提供有力支持。

zhubeibei168的博客 732

getDrawable(int) is deprecated

随着新的 Android API22 getResources().getDrawable()现已弃用. A) drawables without theme attributes ResourcesCompat.getDrawable(getResources(), R.drawable.name, null); You'll get your unstyled

waww116529的专栏 3534

android getdrawable theme,Android getResources().getDrawable() deprecated API 22

1173You have some options to handle this deprecation the right (and future proof) way, depending on which kind of drawable you are loading:A) drawables with theme attributesContextCompat.getDrawable(g...

weixin_36489344的博客 732

android getdrawable theme,Android getResources() getDrawable()弃用API 22

你有一些选项来处理这种弃用正确的(和未来的证明)的方式,这取决于你正在加载哪种类型的可绘制:A)具有主题属性的drawablesContextCompat.getDrawable(getActivity(), R.drawable.name);您将获得一个风格化的Drawable作为您的活动主题指示。这可能是你需要的。B)没有主题属性的drawablesResourcesCompat.getDra...

weixin_29271263的博客 846

getResources().getDrawable() deprecated API 22

stackoverflow: https://stackoverflow.com/questions/29041027/android-getresources-getdrawable-deprecated-api-22 You have some options to handle this deprecation the right (and fu...

怪咖先森的博客 1176

Context#getResources().getDrawable()方法过时后的替代方法

博客源址:http://www.jianshu.com/p/e22d9dd93d4a 参考:Android getResources().getDrawable() deprecated API 22 1)使用drawable资源但不为其设置theme主题 ResourcesCompat.getDrawable(getResources(), R.drawable.name,

Android移动开发者的专栏 1万+

Android 'getWidth()' is deprecated 解决方案

'getWidth()' is deprecated 解决方案

zbgoodstudy的博客 2658

代码设置android theme属性,[译]使用Android Theme属性进行个性化

你也许注意到context.getResources().getColor(R.color.some_color_resource_id);AndroidStudio会提示Resources#getColor(int)方法在Marshmallow版本已经过时了,可以使用Resources#getColor(int, Theme)来代替。你也许知道最简单的处理方法是调用:ContextCompat....

weixin_42565402的博客 1381

java floatmath_【Android】解决FloatMath类中方法在API 23以后不存在问题

1.问题原因分析在Android SDK更新至23以上时,我们会发现之前在某些地方因计算需要使用到的FloatMath类中的方法如FloatMath.ceil()与FloatMath.sin()等都报错并提示不可用了,FloatMath源码如下:package android.util;/*** Math routines similar to those found in {@link java...

weixin_36260304的博客 405

用生命周期规范组件化流程

写在前面 1. 组件划分 架构 宿主壳、调试壳 组件层 基础层 MVC、MVP、MVVM 如何下沉 Utils 规范:使用 Kotlin 静态方法 单例模式 res 规范:命名清晰 string.xml asset 特殊组件 CommonResource CommonData CommonBase CommonSDK 2. 组件创建 从原有代码中拆分出的新组件 为...

weixin_33676492的博客 683

'getDrawable(int)' is deprecatedgetDrawable过时

getDrawable(int)API 215.0)已经过时了 5.0之后使用: ContextCompat.getDrawable(context, R.drawable.your_drawable) 例如: imageView.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.icon));

yechaoa 3957

Drawable Resources

drawable资源是一个图形的通用概念,它表示这个图形可以绘制到屏幕上,可以使用API接口获取,例如getDrawable(int);或应用到另外的XML资源属性中,例如android:drawable和android:icon。有以下几种drawable资源。 Bitmap File——一个位图图形文件(.png,.jpg,.gif)[此处指出了位图就是我们真是可见的图片]。创建一个Bitm

sean_xiang的专栏 1175

AndroidgetResources().getDrawable() 过时的解决方法

当你这个Drawable不受主题影响时 ResourcesCompat.getDrawable(getResources(), R.drawable.name, null); 当你这个Drawable受当前Activity主题的影响时 ContextCompat.getDrawable(getActivity(), R.drawable.name); 当你这个Drawabl

zhengzhihao1的专栏 4325

Android getResources()。getDrawable()已弃用API 22

With new android API 22 getResources().getDrawable() is now deprecated. 使用新的android API 22,现在不建议使用g

xfxf996的博客 1467

Android apk读取资源文件过程详解

Android资源热修复详解第二篇,Android apk读取资源文件过程详解

jieqiang3的专栏 6647

[译]使用Android Theme属性进行个性化

原文地址——Styling Colors & Drawables w/ Theme Attributes。你也许注意到context.getResources().getColor(R.color.some_color_resource_id); AndroidStudio会提示Resources#getColor(int)方法在Marshmallow 版本已经过时了,可以使用 Resources#

小黑屋 8968

面板数据-企业互联网数据中心.xlsx

详细介绍及样例数据:https://blog.csdn.net/li514006030/article/details/156828041

Win7_OEM证书序列号导入工具v2.6

Win7_OEM证书序列号导入工具v2.6,

上一篇: IntentService详解
下一篇: Android中在fragment A里面点击button跳转到fragment B实现方法
solocoder222
博客等级 码龄8年 129粉丝 69原创
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值