This should do the job:
TypedValue typedValue = new TypedValue();
Theme theme = context.getTheme();
theme.resolveAttribute(R.attr.theme_color, typedValue, true);
@ColorInt int color = typedValue.data;
Also make sure to apply the theme to your Activity before calling this code. Either use:
android:theme="@style/Theme.BlueTheme"
in your manifest or call (before you call setContentView(int)
):
setTheme(R.style.Theme_BlueTheme)
in onCreate()
.
I've tested it with your values and it worked perfectly.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…