Sohail Budhawani
Aug 31, 2018 · 1 min read

My TextView is throwing an UnsupportedOperationException when I use ?attr/primaryColor1 for color

attrs.xml

<resources>

...

<attr name="primaryColor1" format="reference" />

</resources>

styles.xml

<style name="AppThemeGreen" parent="Theme.AppCompat.Light">
...
<item name="primaryColor1">@color/weird_green</item>
</style>

androidManifest.xml

<application
...
android:theme="@style/AppThemeGreen">

TextView

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/this_week"
android:textColor="?attr/primaryColor1" />
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade