Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference in naming xml between res-auto and com.package.name - android

Tags:

android

xml

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.

like image 201
david Avatar asked Sep 24 '14 02:09

david


1 Answers

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.

like image 118
Zar E Ahmer Avatar answered Sep 28 '22 10:09

Zar E Ahmer