Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio XML closing tag indentation

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?

like image 342
hdt80 Avatar asked May 05 '26 03:05

hdt80


2 Answers

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.

like image 94
Bob Avatar answered May 06 '26 18:05

Bob


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.

like image 43
HaroldSer Avatar answered May 06 '26 16:05

HaroldSer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!