'Custom view custom attribute not being set without @{}

So I've got a custom view with this attribute:

    private var mLabelText: String = "DEFAULT"
    var labelText: String
        set(value) {
            if (mLabelText != value) {
                mLabelText = value
                invalidate()
            }
        }
        get() { return mLabelText }

And defined in attr.xml as

    <declare-styleable name="CustomView">
        <attr name="labelText" format="string"/>
    </declare-styleable>

Now if I try to do this in my layout XML to set the value, it doesnt work (the text still shows 'DEFAULT')

        <CustomView
            ...
            app:text="NewText" />

However, if I do this, it works:

        <CustomView
            ...
            app:text="@{`NewText`}" />

So what gives? How come views like TextView allow me to do android:text="Text" instead of having to write android:text="@{`Text`}, but my own custom view wont?



Solution 1:[1]

Mike's comments answer the confusion I had about the different syntaxes.

What I ended up doing ultimately is to inherit the existing android TextView. TextView has a bunch of stuff I needed like font, font size etc, so it was just simpler to inherit rather than re-implement it myself.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Olli