KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I want to use colors from a Theme to apply it to some HTML my app is rendering. I am wondering if I can do that? I am looking to use colors like they are specified in themes.xml: <item name="colorBackground">@android:color/background_dark</item> <item name="textColorPrimary">@android:color/primary_text_dark</item> So looking at them they are declared in the same way. So I thought I could access them in the same way too. That is not the cause though. When trying to access those values this way: TypedValue tv = new TypedValue(); getTheme().resolveAttribute(android.R.attr.colorBackground, tv, true); System.out.println("tv.string=" + tv.string); System.out.println("tv.coerced=" + tv.coerceToString()); int colorResourceId = getResources().getColor(tv.resourceId); System.out.println("colorResourceId=" + colorResourceId); tv = new TypedValue(); getTheme().resolveAttribute(android.R.attr.textColorPrimary, tv, true); System.out.println("tv.string=" + tv.string); System.out.println("tv.coerced=" + tv.coerceToString()); colorResourceId = getResources().getColor(tv.resourceId); System.out.println("colorResourceId=" + colorResourceId); I get this as a result: I/System.out( 1578): tv.string=null I/System.out( 1578): tv.coerced=#ffffffff I/System.out( 1578): colorResourceId=-1 I/System.out( 1578): tv.string=res/color/primary_text_light.xml I/System.out( 1578): tv.coerced=res/color/primary_text_light.xml I/System.out( 1578): colorResourceId=-16777216 The results are different. The first one actually gives me the color "#fffffff" which would work for me, the second one only gives me an xml. Do I need to jump through a few more hoops here to resolve the actual color? Does my original intention work at all? Maybe it won't work, because colors could be arbitrary drawables?
Tags (comma-separated)
Save Edits
Cancel