Java tutorial
//package com.java2s; import android.content.Context; import android.util.TypedValue; public class Main { /** * helper method to get the color by attr (which is defined in the style) or by resource. * * @param ctx * @param attr * @param res * @return */ public static int getThemeColorFromAttrOrRes(Context ctx, int attr, int res) { int color = getThemeColor(ctx, attr); if (color == 0) { color = ctx.getResources().getColor(res); } return color; } public static int getThemeColor(Context ctx, int attr) { TypedValue tv = new TypedValue(); if (ctx.getTheme().resolveAttribute(attr, tv, true)) { return tv.data; } return 0; } }