Can you open an XML file in android studio but with different code style rules than the normal xml files?

97 views Asked by At

In my application I have some xml files which I end with .layout, I open them as xml files (because that is what they are)

The problem is that when I press ctrl-alt-l to fix idents and things like that it also rearranges all my attributes

I want the attributes to be rearranged in android studio xml files but not in my layout files

so is there a way to have a specific file type be opened as an xml file but with a custom code style?

1

There are 1 answers

1
bijaykumarpun On

I'm not going to pretend this will do exactly what you want but let me guide you close to what you want. See if you can reach there!

Goto > File | Settings | Editor | Code Style | XML

Here you will see four main tabs where you can configure how code is reformatted.

Out of the four tabs see under Tabs and Indents to set various indentation attributes while reformatting.

And under Arrangement you can see the arrangement rules, which determine in which order the attributes are to be ordered when you reformat. You can clear all the rules to stop the automatic arrangement altogether, but do as you need. There is also option to Force rearrange that you can again use as you need.

Pro Tip You can save and use multiple such settings by switching the Scheme option at the very top.

I know this doesn't quite answer your question but hope it helps you in a way.

Thanks for looking.