get Color from Context - Android Graphics

Android examples for Graphics:Text Color

Description

get Color from Context

Demo Code


import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;

public class Main{
    public static final int getColor(@NonNull Context context, int id) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
            return ContextCompat.getColor(context, id);
        return context.getResources().getColor(id);
    }/*from   w  ww.j a  va  2s  .  c o  m*/
}

Related Tutorials