Is it possible to shorten the names of user names?

Let's say that I created a custom view called MyView and want to use it in xml, and the view is in the com.example package. I need to do something like this:

 <com.example.MyView ...... /> 

I need to write a package name every time I use a view. What if I have a long package name?

 <what.a.long.long.long.loooooong.packagename.MyView ...... /> 

It just looks ugly. Is it possible to shorten the package name? Do I need to do something in the AndroidManifest.xml file?

+6
source share
2 answers

Define your own namespace:

 <Layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:x="what.a.long.long.long.loooooong.packagename." > <x:MyView> </x:MyView> </Layout> 

xmlns:x indicates that all tags starting with <x: should be viewed in the package that is defined in the namespace definition ( what.a.long.long.long.loooooong.packagename. in this case).

You can even use the namespace inside the tag itself:

 <x:MyView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:x="what.a.long.long.long.loooooong.packagename." /> 
+3
source

You can use my XmlTag library. It allows you to use the short name of each View that you comment using @XmlTag .

XmlTag in action

+1
source

All Articles