0

Is it not possible to simplify the name of a custom element in an Activity XML file?

<com.library.CustomView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res/com.example.library.customview" android:id="@+id/myView" app:newAttr="value" /> 

Say for example I have a CustomView control. Do I always have to put "com.library." in front of "CustomView" or is it possible to use xmlns:custom in a FrameLayout so that I don't need to?

This is what I would like to see (if possible):

<CustomView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res/com.example.library.customview" android:id="@+id/myView" app:newAttr="value" /> 

1 Answer 1

1

No. You must specify the fully qualified name of the custom view class. The custom attribites belong to a different namespace. So you nee to have

 http://schemas.android.com/apk/res/[your package name]. 

That is why you have

 xmlns:app="http://schemas.android.com/apk/res/com.example.library.customview" 

It is necessary to specify fully qualified name of the custom view and hence

 <com.library.CustomView 

http://developer.android.com/training/custom-views/create-view.html

The docs does not mention any other solution.

Edit:

There seems to be a workaround as mentioned in the below link. Notice comments on both answers. The authors feels there is a little overhead involved. So its left you to use the below although i recommend you to follow the above method mentioned in the docs.

Using custom Views in XML without using fully-qualified class name

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

1 Comment

Thanks for clarifying. I'll stick with the fully qualified names. I guess it does make things clearer.. even if it isn't 'neat' :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.