I have a custom viewholder class that gets a color from an attribute in the android namespace in the constructor:
int mDefaultPrimaryColor = GetColor(context, android.R.attr.colorPrimary);
....
public static int getColor(Context context, int attr)
{
TypedArray ta = context.obtainStyledAttributes(new int[]{attr});
int color = ta.getColor(0, 0);
ta.recycle();
return color;
}
Later on the bind method eventually sets the color:
someTextView.setTextColor(mDefaultPrimaryColor);
I would like to override the android.R.attr.colorPrimary value in my app through XML without modifying Java code so that the value is different than the one being set in the SDK.
I tried to override this value in my themes.xml:
<resources>
<style name="MyAppTheme" parent="@android:Theme.DeviceDefault.NoActionBar">
<item name="android:colorPrimary">@color/my_color</item>
</style>
</resources>
However, the color I am seeing in the Android emulator is not the color I have set for my_color. Is there a way to override the android.R.attr.colorPrimary with a color I defined in my app? What am I doing wrong?
EDIT: The theme is already set in the manifest file. Updated the code snippet to be more exact.