是否可以为包名称创建一个昵称,我可以在 xml 文件中引用它?
我不想写完整的包名,例如 com.example.go.deck.today 而是我可以创建一个别名并引用该别名吗?
我想在 android/layout XML 文件中引用别名或昵称而不是包名称。
不,抱歉,这是不可能的,至少不能直接在 Android 工具集中。
Android by itself does not provide such facility. However you can use the ant to do it for you. You could write a custom build.xml, customizing the target <target name="-code-gen">
to do token replacement before the R
class is generated. You could add the rule :
<replace file="targetFile" token="@PACKAGE_ALIAS@" value="com.example.go.deck.today"/>
this would replace every occurrence of @PACKAGE_ALIAS@
by com.example.go.deck.today
in the targetFile
.
I am not an ant
specialist but based on past experience I would say that it would not be hard to write a rule that could scan all file in the res
dir.