Android Studio XML closing tag indentation

Android Studio XML closing tag indentation

android studio xml formatting broken
android studio xml format order
android studio xml code style
android studio xml hint not showing
android studio layout xml files code changes automatically from default
android xml style guide
preview is disabled in android studio
preview in android studio

I have a TextView defined as

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/nav_header_vertical_spacing"
        android:text="Semita"
        android:textAppearance="@style/TextAppearance.AppCompat.Body1"
        />

But I don't like the closing tag on the same indentation level as the attributes. When I hit backspace I'd like it to look like:

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/nav_header_vertical_spacing"
        android:text="Semita"
        android:textAppearance="@style/TextAppearance.AppCompat.Body1"
    />

which is what I'd like, I instead get:

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="@dimen/nav_header_vertical_spacing"
    android:text="Semita"
    android:textAppearance="@style/TextAppearance.AppCompat.Body1"/>

where the /> is on the same level as the attributes. How can I change this behavior?


Place the cursor before the /> and press Shift + Tab if you are using Mac.

Pressing Tab adds 4 spaces and pressing Shift + Tab moves 4 spaces back.

XML Editing Improvements, Android Studio XML closing tag indentation - android. Body1" /> But I don't like the closing tag on the same indentation level as the attributes. When I hit  Now, it looks at the surrounding XML context and decides how much to indent the next line. This means that if you for example are editing the attribute list of an element tag that you have not yet closed, the next line will indent one extra level for the indented attributes, and similarly, if you've closed the open tag but haven't added an end


There is auto-indentation if you have already your closing tags, simply press "Ctrl+Alt+I". This will auto-indent whatever block you are highlighting.

Android Studio XML closing tag indentation, For the manifest, this might almost be survivable. However, lots of things in Android are dependent upon XML element order, such as the children  I am using AS since 4 years. After last update I observed unexpected auto-formatting of XML layout (while typing and with Code-> Reformat Code too). Here is an example: When I started typing relative layout, it expanded start tag, width property, height property and closing tag in the same line. Properties starts after indentation.


While Bob's answer should solve your problem. You should consider following this format:

<TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/nav_header_vertical_spacing"
        android:text="Semita"
        android:textAppearance="@style/TextAppearance.AppCompat.Body1">
</TextView>

Android Studio 3.5 Upgrade XML Reformatting Problems, The XML for this child tag, which is shown in Figure 4-1 and below in full, uses indentation for easy parameter views, as well as setting Android Text class constants which is really how things should have been set up initially by Android Studio. tag; in this case that is the <ConstraintLayout> tag, and its paired closing tag  Almost all attributes in Android XML files has “android:” prefix (or namespace explained later). What’s really helpful, Android Studio editor checks if you have used proper tags, proper attributes and that you closed tags. Common mistake is skipping signs: “”, =, <,> or /.


see

Settings -> Editor -> Code Style -> XML

for xml formatting & indentation

but you should use node starting and full ending tag for this

there is no option to move short closing node tag to new line with current ide options instead use

// node 

<tag attr="val"            //  starting tag
     name="alalala">      
    i'm body               //  tag body  
</tag>                     //  closing tag

or post your issue here with feature request

https://youtrack.jetbrains.com/issues

Android Apps for Absolute Beginners: Covering Android 7, Shortcuts: Visual Studio. On this page · XML How to align when tabs are used for indents. Property names: Possible values: use_spaces : Use spaces (looks aligned on any tab size) <?xml version='1.0' encoding='utf-8'?>. Copied! Line breaks after start-tag and before end-tag in multiline elements. Property names  The Android Studio has an option where you can browse the most recently opened files on the go. Just press CTRL + E for windows and Command + E for mac and a list of recently opened files will popup.


Go to Settings -> Editor -> Code Style -> XML and select Android tab In Layout Files section check "Insert line break after last attribute"

XML - Formatting Style - Help, Tab size. In this field, specify the number of spaces included in a tab. Indent to have short comments kept in one line with the opening and closing tags. Reformat XML text pasted from the clipboard. On completion of end tag. Reformat the element when the end tag is completed. Mixed Content. Format mixed content by default. Attempt to reformat mixed content, except when the content is found in an xml:space="preserve" scope. This setting is the default.


Code Style. Java - Help, Can we change XML format (i.e. create a new language which doesn't have the verbosity issue)? Yes, we can. In order to completely migrate to the "better XML"  XML to JSON is an Android Studio Library which converts easily XML to JSON and JSON to XML. It is fully configurable so that you can change for example attribute names. It is easy to integrate with gradle .


XML/HTML: Do we need the element name in closing tags , You can control how the text appears with TextView attributes in the XML layout file. This practical Add a ScrollView to the layout to enable scrolling a TextView element. In Android Studio create a new project with the following parameters: Enter \n to represent the end of a line, and another \n to represent a blank line. Extensible Markup Language (XML) is a set of rules for encoding documents in machine-readable form. XML is a popular format for sharing data on the internet. Websites that frequently update their content, such as news sites or blogs, often provide an XML feed so that external programs can keep abreast of content changes.


1.3: Working with TextView Elements · GitBook, Developing Android 10 (Q) Apps Using Android Studio 3.5, Java and Android to the ConstraintLayout parent must be nested within the opening and closing tags. as a child of the ConstraintLayout: <?xml version="1.0" encoding="utf-8"?​> the screen (though indented 16dp by the padding assigned to the parent layout). But it seems to me that we could cut a lot of the excess from XML simply by stripping away the names from the closing tags. With proper indentation readability shouldn't be an issue (it should be an improvement, if you ask me), and since they're not structurally required any decent XML editor/viewer could easily be made to strip/hide or add them.