Reputation: 391
How can I comment in xml file of android layout. I have seen Comments in Android Layout xml - but I wanted to comment inside a parent.
When I try to do that I get an error in eclipse:
<Button android:text="Button"
<!-- this is a comment -->
android:id="@+id/Discon" >
</Button>
From the background knowledge of xml, I came to know that we cannot add comments in attributes.
Is there any way of removing the id as attribute and specifying it as element?
Or is there any way to add comments inside attributes of elements?
Upvotes: 32
Views: 34857
Reputation: 1395
Use Below Code for comment in Android Studio:
Comment / uncomment a block of code. Ctrl + Shift + "/"
Comment / uncomment a line of code. Ctrl + "/"
Upvotes: 1
Reputation: 933
XML does not allow to comment between tags () which means you can't place comments to attributes as they'd be inside its tag. You can't remove an attribute and place it outside its tag, because then it is no longer an attribute.
In short, what you're trying to do, in the way you try to do it, it simply cannot be done.
Upvotes: 1
Reputation: 61
I use Android Studio, So i can tell u XML comment for A.S only.
Simply select the part of code you want to make it comment and
press (Ctrl+shift+?) It will add <1-- your Code -->, Here 1 is (Shift+1)( exclamation mark)
Remember one more thing , Here is one exception : Example
<TextView
android:id="@+id/T_HomeworkMax1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FF1E0101"
android:textAppearance="?android:textAppearanceSmall"
android:layout_marginStart="95dp"
android:text="Max" />
<TextView
android:id="@+id/T_HomeworkMin1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FF1E0101"
android:layout_marginStart="140dp"
android:textAppearance="?android:textAppearanceSmall"
android:text="Min" />
Here,You can not select just one or two lines from the code, You have to select full Node(TextView).
<!-- <TextView
android:id="@+id/T_HomeworkMax1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FF1E0101"
android:textAppearance="?android:textAppearanceSmall"
android:layout_marginStart="95dp"
android:text="Max" />-->
<TextView
android:id="@+id/T_HomeworkMin1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FF1E0101"
android:layout_marginStart="140dp"
android:textAppearance="?android:textAppearanceSmall"
android:text="Min" />
Now, First TextView is Comment.
Upvotes: 3
Reputation: 5028
Well not technically a comment, buy you can do
<Button comment="write whatever you want here" android:text="Button" ...
Or if you want to temporarily remove an attribute, remove the android:
from the name.
Basically Android ignores everything without the android:
namespace.
Upvotes: 12
Reputation: 8190
you cannot embed a comment inside a tag. between tags it's not a problem
<!--
this is a comment
-->
<Button android:text="Button"
android:id="@+id/Discon" >
</Button>
if you want to temporary comment out an attribute (if that's what you want to know) you will have to move it ouside the tag and comment it there.
<Button android:text="Button"
android:id="@+id/Discon"
>
</Button>
==>
<!-- android:id="@+id/Discon" -->
<Button android:text="Button"
>
</Button>
Upvotes: 37