Mar*_*ara 1 java colors deprecated drawable android-studio
这是一个简单的代码,错误消息没有说明确切的弃用位置。
package com.dev.marcellocamara.pgm.Helper;
import android.content.Context;
import android.graphics.drawable.Drawable;
import com.dev.marcellocamara.pgm.R;
public class CardHelper {
public static Drawable getBackground(Context context, int drawable){
switch (drawable){
case 1 : {
return (context.getResources().getDrawable(R.drawable.card_yellow));
}
case 2 : {
return (context.getResources().getDrawable(R.drawable.card_purple));
}
case 3 : {
return (context.getResources().getDrawable(R.drawable.card_green));
}
default : {
return null;
}
}
}
public static Drawable getFlag(Context context, int flag) {
switch (flag){
case 1 : {
return (context.getResources().getDrawable(R.drawable.flag1));
}
case 2 : {
return (context.getResources().getDrawable(R.drawable.flag2));
}
case 3 : {
return (context.getResources().getDrawable(R.drawable.flag3));
}
default : {
return null;
}
}
}
public static int getColor(Context context, int card) {
switch (card){
case 1 : {
return (context.getResources().getColor(R.color.card1));
}
case 2 : {
return (context.getResources().getColor(R.color.card2));
}
case 3 : {
return (context.getResources().getColor(R.color.card3));
}
default : {
return 0;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
如代码所示,我正在返回可绘制或颜色。这很简单。需要更改的警告在哪里?如何跳过此警告,继续返回可绘制对象和颜色?
在Android API 22 getResources().getDrawable()中已弃用。现在您应该使用此方法getDrawable (int id, Resources.Theme theme)
并且getColor (int id)已在API 23中弃用。现在getColor(int, android.content.res.Resources.Theme)改为使用。
签出更多信息:https : //developer.android.com/reference/android/content/res/Resources
| 归档时间: |
|
| 查看次数: |
112 次 |
| 最近记录: |