Hi Dianne.

Thanks very much, almost there.

I understand the procedure, it would do what I want, but I run into an
exception:

D/NewsRobDefaultExceptionHandler( 1839): Caused by:
java.lang.UnsupportedOperationException: Can't convert to color: type=0x2
D/NewsRobDefaultExceptionHandler( 1839): at
android.content.res.TypedArray.getColor(TypedArray.java:273)
D/NewsRobDefaultExceptionHandler( 1839): at
android.graphics.drawable.GradientDrawable.inflate(GradientDrawable.java:647)
D/NewsRobDefaultExceptionHandler( 1839): at
android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:788)
D/NewsRobDefaultExceptionHandler( 1839): at
android.graphics.drawable.Drawable.createFromXml(Drawable.java:729)
D/NewsRobDefaultExceptionHandler( 1839): at
android.content.res.Resources.loadDrawable(Resources.java:1690)

This happens when using it the way we described here in a drawable xml.
However to better understand the error I used it on other attributes and
when using it on the background attribute of a View it works. Maybe this
approach is incompatible with drawables that are expressed in xml?

Btw. Is there any way to get the actual #rgb string for a color from a
theme?

Cheers,
Mariano

On Tue, May 11, 2010 at 8:02 AM, Dianne Hackborn <hack...@android.com>wrote:

> You need to define an attribute for your value:
>
> <attr name="myColor" format="color" />
>
> Then make a custom theme that supplies a value for it:
>
> <style name="MyTheme" parent="android:Theme">
>     <item name="com.my.package:myColor">#ff808080</item>
> </style>
>
>  And now you can reference that value from other XML:
>
> <shape xmlns:android="http://schemas.android.com/apk/res/android
> "
>         android:shape="rectangle">
>     <gradient android:startColor="?com.my.package:myColor"
>
>             android:endColor="#66FFFFFF"
>             android:angle="270" />
> </shape>
>
>
> Note that "com.my.package" is your manifest's package name.
>
> Also I just wrote this by hand so I won't guarantee it is completely right.
> :}
>
> On Mon, May 10, 2010 at 11:02 AM, Mariano Kamp <mariano.k...@gmail.com>wrote:
>
>> Hmmh, also no answer to this question on themes. Maybe the answer cannot
>> be given with two lines? So let me explain what I would expect step by step
>> and you stop me were I deviate from the Golden Path? I'll try yes/no
>> questions.
>>
>> In the simplest terms I would expect that in every place I can specify a
>> color in RGB (#ffff) I could also specify a symbolic name instead. This
>> should work like @color/xyz, but with one more level of indirection that
>> lets me switch between themes, like dark and light.
>>
>> Is that possible?
>>
>> I would expect those themes to be applicable to (a) widgets, (b) drawables
>> (see the mentioned example) and (c) when I need to style something myself
>> like HTML. Are (a) - (c) possible?
>>
>> Furthermore I would expect that I could define style keys myself, but I
>> got the impression that only keys from the "android" namespace can be used?
>> That lead me to believe that you can't define abstract colors, but only
>> styles for specific attributes used in the widgets' implementations.
>>
>> And again, if there is any meaningful documentation I would be happy to
>> read it. Just send me the link or name of the book.
>>
>>
>> On Sat, May 8, 2010 at 3:26 PM, Mariano Kamp <mariano.k...@gmail.com>wrote:
>>
>>> Hi,
>>>
>>> I have trouble 
>>> (example<http://groups.google.com/group/android-developers/browse_thread/thread/5b4ce3e49a1b63d2/>)
>>> wrapping my head around styles/themes. Can somebody help me or point me to
>>> actual documentation?
>>>
>>> Let's say I have a drawable that I want to use as the background of a
>>> layout:
>>>
>>> <shape xmlns:android="http://schemas.android.com/apk/res/android";
>>>         android:shape="rectangle">
>>>         <gradient android:startColor="#9F9FA4" android:endColor="#66FFFFFF"
>>>                 android:angle="270" />
>>> </shape>
>>>
>>>
>>> Now I want to have a dark and a light theme. Depending on the chosen theme 
>>> I want to have a different value for startColor and endColor. How do I do 
>>> that? I am aware of extending themes, but what do I put into the items? How 
>>> do I reference those new values then?
>>>
>>>
>>> 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 android-developers@googlegroups.com
>> To unsubscribe from this group, send email to
>> android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com>
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>>
>
>
>
> --
> Dianne Hackborn
> Android framework engineer
> hack...@android.com
>
> Note: please don't send private questions to me, as I don't have time to
> provide private support, and so won't reply to such e-mails.  All such
> questions should be posted on public forums, where I and others can see and
> answer them.
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>

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

Reply via email to