I have a cusom view derived from TableLayout, and I need to declare String property Title, like this:
<com.mycompany.controls.NavigationControllerView
xmlns:app="http://schemas.usetech.com/apk/res/onroad"
title="@string/nav_title"
...
/>
(to be able specify value via resource reference). I've specified this property in values/attrs.xml:
<declare-styleable name="NavigationControllerView">
<attr name="title" format="string"/>
...
</declare-styleable>
In my code I'm trying:
public class NavigationControllerView extends TableLayout {
public NavigationControllerView(Context context, AttributeSet attrs) {
super(context, attrs);
View.inflate(getContext(), R.layout.inc_header, this);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NavigationControllerView);
CharSequence title = a.getString(R.styleable.NavigationControllerView_title);
if (title != null)
setTitle(title.toString());
}
...
but no luck, title is always null. Do you see where I'm wrong?
You should use
<com.mycompany.controls.NavigationControllerView
xmlns:app="http://schemas.android.com/apk/res/onroad"
app:title="@string/nav_title"
... />
do not miss app: prefix. Also correct namespace uri should be used.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With