Search code examples
regexxmlandroid-studiopluginscopy-paste

Plugin to help copy/paste XML in android studio according to some pattern?


I use android studio for creating android apps. While designing the UI I mostly find myself copy pasting my custom made components to test different things out and to see how would they look when I actually populate the view with my component using some adapter. But when I duplicate my components I manually have to update there id's and other attributes in XML according to needs. But those changes mostly have some sort of pattern which I can always define using a regular expression.

So, in short is there any tool for android studio that can help me copy/paste XML by defining some pattern via regex or something else ?

Or should I see this as an opportunity to create my own plugin and start coding right away.


Solution

  • Android Studio (Version 3.3+) supports Live Templates, that you can make as per your use. These can be for .java as well as .xml file formats. See this official Android Developer Youtube channel.

    More resources regarding templates in Android Studio:

    You can also try to make repeatedly used classes, activities etc into a library package and reuse them across your projects. Add some tests to them to make sure they work as intended and with some CI/CD scripting and gradle plugins (like gradle-use-latest-versions-plugin) you can have them automatically upgrade to use latest dependency versions etc. Then all you'd need to do is pull them from a repository or include them as a library in your projects to reduce code redundancy.

    Hope this helps.