Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我的类代码中不推荐的API在哪里?我搞不懂_Java_Android Studio_Colors_Drawable_Deprecated - Fatal编程技术网

Java 我的类代码中不推荐的API在哪里?我搞不懂

Java 我的类代码中不推荐的API在哪里?我搞不懂,java,android-studio,colors,drawable,deprecated,Java,Android Studio,Colors,Drawable,Deprecated,这是一个简单的代码,错误消息没有说明不推荐使用的确切位置 正如代码所说,我将返回可绘制或颜色。很简单。需要更改的警告在哪里?如何跳过此警告,继续返回可绘制和颜色?在Android API 22中,getResources.getDrawable已被弃用。现在您应该使用这个方法getDrawable int-id,Resources.Theme API 23中不推荐使用getColor int id。现在改用getColorint,android.content.res.Resources.The

这是一个简单的代码,错误消息没有说明不推荐使用的确切位置

正如代码所说,我将返回可绘制或颜色。很简单。需要更改的警告在哪里?如何跳过此警告,继续返回可绘制和颜色?

在Android API 22中,getResources.getDrawable已被弃用。现在您应该使用这个方法getDrawable int-id,Resources.Theme

API 23中不推荐使用getColor int id。现在改用getColorint,android.content.res.Resources.Theme

有关更多信息,请查看此链接:

Android API 22中的getResources.getDrawable已被弃用。现在您应该使用这个方法getDrawable int-id,Resources.Theme

API 23中不推荐使用getColor int id。现在改用getColorint,android.content.res.Resources.Theme

有关更多信息,请查看此链接:

我不知道。。。现在我使用的是ContextCompat.getColorcontext,R.color.color。还不确定如何在Resources.theme中使用主题。如何从Kotlin调用android.content.res.Resources.theme?不知道。。。现在我使用的是ContextCompat.getColorcontext,R.color.color。还不确定如何在Resources.theme中使用主题。如何从Kotlin调用android.content.res.Resources.theme?
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;
            }
        }
    }

}