5

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?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Ups, you are right, but even using app prefix Title is null, neither specifying resource reference neither providing direct string value
maybe you're using whong custom namespace? I use xmlns:app="schemas.android.com/apk/res/'packagepath'" where 'packagepath' - root package path
Right! Thank you, schema really should be in form: schemas.android.com/apk/res/com.mycompany.myapp Please fix xmlns:app in your answer and I'll mark it as correct

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.