7

I have seen custom xml with :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res-auto"

and

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/com.package.custom"

whats the difference between these two separate names?

  1. Is the latter only points to default location like your package?
  2. Is the former points to the reference lib ?

thanks.

1 Answer 1

12

If we add a new custom view and its attributes inside our project, you add this at the beginning of your layout:

xmlns:custom="http://schemas.android.com/apk/res/your_main_app_package

If the new custom view is inside a library project linked to your project, you add this:

xmlns:custom="http://schemas.android.com/apk/res-auto

Note: This problem has been fixed in ADT revision 17+ . For any services or Activities, declare the namespace as follows:

xmlns:custom="http://schemas.android.com/apk/res-auto"

The suffix res-auto will be replaced at build time with the actual project package, so make sure you set up your attribute names to avoid collisions if at all possible.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.