Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio 3.2.1, XML bad indent format

After updating to Android Studio 3.2.1 the XML files format is very annoying and bad, how can we fix it? Can we change it from somewhere in settings to previews type?

new format

like image 766
Mohammad Hadi Avatar asked Nov 07 '18 19:11

Mohammad Hadi


People also ask

Does XML care about indents?

No, the indentation does not matter in XML documents.

How do I set an indentation in XML?

To turn it on or off for the Text editing mode,open the Preferences dialog box (Options > Preferences), go to Editor > Format > XML, and select/deselect the Schema-aware format and indent option.

How do I set indentation for the Android formatter?

By default, the formatter will use the Android-defaults for indentation: 4 space characters. However, there is a setting for turning this off and making the indentation use the Eclipse XML indentation settings instead (which defaults to one tab character). Here are the current options related to the XML formatter:

How to format code in Android Studio?

We are going to discuss three different methods with the help of which we can format the code in our Android Studio. In this method, we simply have to navigate to the file in which we have to format our code. After opening the file we have to simply press the shortcut key as Ctrl+Alt+L to reformat the code in your file.

How do I increase the font size in Android Studio code editor?

In the Settings window, navigate to Editor > Font. Increase the font size. Click OK. This section describes known issues related to the code editor. There are some known interactions between the iBus daemon on Linux and Android Studio.

What is the Eclipse XML formatter for Android plugins?

The Android Eclipse plugins now provides its own custom XML formatter. This formatter replaces the default Eclipse XML formatter, but there is a setting you can uncheck to revert to the default Eclipse XML formatter. The new formatter basically formats the XML the "standard".


3 Answers

On Android Studio 3, Go to :

Preferences > Editor > Code style > XML then on Scheme switch to Default instead of Project.

You can then use those shortcuts to indent your code:

Windows:

Ctrl + Alt + L

macOS:

Option + Command + L

like image 109
Badr Avatar answered Oct 17 '22 22:10

Badr


You can edit your code styles under File > Settings > Editor > Code Style > XML

Code Style Settings

If you want to preview a specific file, just paste that file's contents into the preview window.

like image 21
Chris Stillwell Avatar answered Oct 18 '22 00:10

Chris Stillwell


Open File > Settings > Editor > Code Style > XML

Now in layout file make sure you have selected wrap attributes as Wrap always.
Screenshot

like image 10
efr Avatar answered Oct 17 '22 23:10

efr