Hi,

I want to use colors from a Theme to apply it to 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="colorForeground">@android:color/bright_foreground_dark</item>
..
        <item name="colorBackground">@android:color/background_dark</item>
..
        <item
name="textColorPrimary">@android:color/primary_text_dark</item>
..

So it looks to me those are declared in the same way.

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?

I didn't find any relevant documentation, but if you know any, just point me
there please.

Btw. I also tried obtainStyledAttributes(), but this had basically the same
issues.

Cheers,
Mariano

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to