Hi,

I have declared a styleable like this:

<declare-styleable name="Test">
    <attr name="myString" format="string" />
    <attr name="myNumber" format="integer" />
</declare-styleable>

I'm using this with the following java code in a constructor of a
custom View class:

TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Test,
defStyle, 0);
String str = a.getString(R.styleable.Test_myString);
int num = a.getInt(R.styleable.Test_myNumber, -1);
a.recycle();
Log.d("Test", "string: " + str);
Log.d("Test", "number: " + num);

It works as expected when I set the attributes in the layout xml, and
it also works when I define a style with these attributes and use the
style from the layout xml. But somehow I cannot get it to work when I
set the attributes in the theme:

<style name="MyTheme" parent="@android:style/Theme">
    <item name="myString">foobar</item>
    <item name="myNumber">12345</item>
</style>

When I do this, I get the following output:
string: Avbryt
number: 12345

So obtaining the value of the number works, but the string contains a
bogus value, which seems to be the value of an random android string
resource. I tested this on the emulator 2.2 and 2.3.3.
I also tried to use a package prefix <item
name="com.mypackage:myString"> but it does not make any difference.

Why can't I access a string the same way like a number? Am I doing
something wrong? How can I get the value of the string?

I'm doing this because I want to use a custom font from the asset
directory.

Any help is appreciated.

-- 
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