AttributeSet value returns @2131296269 - what is it and how to use?

If I define some view in xml like:


and then at init with AttributeSet:

public AlphabetButton(Context context, AttributeSet attrs) {
    super(context, attrs);

    if (attrs!=null){

        String textSizeAttribute = attrs.getAttributeValue("", "textSize");

this textSizeAttribute value is like:

05-01 16:00:21.154: I/AlphabetButton(8738): textSizeAttribute @2131296269

which I assume is something like a link via R to needed attribute. The question is how to evaluate it? I tried:

if (textSizeAttribute.substring(0, 1).equals("@"))
                Log.i(this, "textSize is "+context.getResources().getDimension(Integer.valueOf(textSizeAttribute.substring(1))));

but this returns wrong value. If I define it like android:texSize="20sp" instead of @dimen-link then textSizeAttribute returns 20.0sp which is correct.

UPDATE I made an research and found that 2131296269 (0x7f09000d) links to correct value in my

    public static final class dimen {
        public static final int alphabet_button_width=0x7f09000b;
        public static final int alphabet_button_height=0x7f09000c;
        public static final int alphabet_button_text_size=0x7f09000d;

and dimens.xml:

<?xml version="1.0" encoding="utf-8"?>

    <dimen name="alphabet_button_width">30dp</dimen>
    <dimen name="alphabet_button_height">30dp</dimen>
    <dimen name="alphabet_button_text_size">20sp</dimen>

but it returns 30 instead of defined 20 can't figure why... Here is the log output:

05-01 16:18:14.284: I/AlphabetButton(9418): textSizeAttribute @2131296269 
05-01 16:18:14.284: I/AlphabetButton(9418): is 2131296269 
05-01 16:18:14.284: I/AlphabetButton(9418): textSize is 30.0

and corresponding code lines:

public AlphabetButton(Context context, AttributeSet attrs) {
    super(context, attrs);

    if (attrs!=null){

        String textSizeAttribute = attrs.getAttributeValue("", "textSize");
        Log.i(this, "textSizeAttribute "+textSizeAttribute);
        Log.i(this, " is "+textSizeAttribute.substring(1));
        Log.i(this, "textSize is "+context.getResources().getDimension(Integer.valueOf(textSizeAttribute.substring(1))));


I'm dealing with this issue as well, and most likely android is scaling the original value of 20 up to 30 according the the screens density, which in your case is most likely 240 DPI, which would yield a scaling factor of 1.5

You can confirm these values by printing the following display metrics (in Mono/C#, needs minor translation for raw Android/Java):

this.ApplicationContext.Resources.DisplayMetrics.Density; this.ApplicationContext.Resources.DisplayMetrics.DensityDpi; this.ApplicationContext.Resources.DisplayMetrics.Xdpi; this.ApplicationContext.Resources.DisplayMetrics.Ydpi; this.ApplicationContext.Resources.DisplayMetrics.WidthPixels; this.ApplicationContext.Resources.DisplayMetrics.HeightPixels;

Need Your Help

Add custom attribute to an HTML input element with C#

c# html web-applications

I'm using the following method to add a custom attribute to a check box:

FilePrg with collections on ZF2

php file-upload collections zend-framework2 post-redirect-get

I need to submit a form which contains some fields along with a collection of max 3 images using fileprg plugin for saving uploaded files in case there has been some validation errors.