Java tutorial
//package com.java2s; // Use of this source code is governed by a BSD-style license that can be import android.content.res.Resources; import android.content.res.Resources.NotFoundException; import android.os.Build; public class Main { /** * @see android.content.res.Resources#getColor(int id). */ @SuppressWarnings("deprecation") public static int getColor(Resources res, int id) throws NotFoundException { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { return res.getColor(id, null); } else { return res.getColor(id); } } }