Package alias name or alias

Is it possible to create an alias for the name of the package that I can reference in an XML file?

I do not want to write the entire package name, for example. com.example.go.deck.today instead, can I create an alias and reference that alias?

I want to pass an alias or nickname instead of the package name in the android / layout XML file.

+7
source share
3 answers

Android alone does not provide such an opportunity. However, you can use ant to do this for you. You can write your own build.xml file by setting the target <target name="-code-gen"> to perform a token replacement before creating the R class. You can add a rule:

 <replace file="targetFile" token="@ PACKAGE_ALIAS@ " value="com.example.go.deck.today"/> 

this will replace every @ PACKAGE_ALIAS@ event with com.example.go.deck.today in targetFile .

I am not an ant specialist, but based on past experience, I would say that it would not be easy to write a rule that could scan the entire file in the res directory.

+5
source

No, sorry, this is not possible, at least not directly in the Android toolbox.

+9
source

Although it is not possible to directly refer to the package name, to use 'resource' in xml or in code:

 package.R.resource_type.resource_name 

and

 @[package:]resource_type/resource_name 

NOTE. The package here does not mean 'java package' , but package == application , so if you are accessing a resource that is defined in your own application, you can skip it. That is why we use @strings/name or directly R.strings.name . Similar to using the resources defined by android, we will use @android:string/name or android.R.string.name

+2
source

All Articles