Java tutorial
//package com.java2s; //License from project: Apache License import android.annotation.SuppressLint; import android.content.res.Resources; import android.os.Build; import android.support.annotation.Nullable; public class Main { @SuppressLint("NewApi") public static int getColorFromResourcesCompat(Resources res, int resId, @Nullable Resources.Theme theme) { return (Build.VERSION.SDK_INT >= 23) ? res.getColor(resId, theme) : res.getColor(resId); } }