У меня есть обычное представление, полученное из TableLayout, и мне нужно объявить свойство String Title следующим образом:
<com.mycompany.controls.NavigationControllerView
xmlns:app="http://schemas.usetech.com/apk/res/onroad"
title="@string/nav_title"
...
/>
(чтобы можно было указать значение через ссылку на ресурс).
Я указал это свойство в values / attrs.xml:
<declare-styleable name="NavigationControllerView">
<attr name="title" format="string"/>
...
</declare-styleable>
В моем коде я пытаюсь:
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());
}
...
но не повезло, заголовок всегда нулевой. Вы видите, где я не прав?