XML attributes order in Android Studio

前端 未结 6 1690
小蘑菇
小蘑菇 2020-12-12 11:30

I\'m facing problem with keeping proper order of XML attributes in Android Studio. As you can see below, the style attribute is between layout_* at

6条回答
  •  孤城傲影
    2020-12-12 12:01

    Finally got it.

    1. Choose File > Settings > Code Style > XML > Set from > Predefined Style > Android
    2. Set File > Settings > Editor > Formatting > Show "Reformat Code" dialog
    3. Run formatting on a XML file (CTRL+ALT+L by default)
    4. You will see a popup window, set the Rearrange entries flag
    5. Disable Reformat Code dialog in the settings

    This way every XML file formatting will set the attributes in a proper order.

    Edit: Starting with Android Studio 0.2.6 release the XML Android style formatting is set by default, but you still have to set the Rearrange Entries flag manually.

    http://tools.android.com/recent/androidstudio026released

    Automatically apply the Android XML code style if a code style hasn't already been customized. This will make it possible to automatically order XML attributes (check the "Rearrange Entries" checkbox in the "Code > Reformat Code..." dialog.)

提交回复
热议问题