0

I am learning Android and want to be able to add line comments to my XML so I can remind myself what things are doing.

Is there an accepted practice for this, or is it possible in Android Studio? I recall reading that comments in XML are hard, so I wanted to know if that was also considered true here.

1
  • You can comment a line using the same what you use on HTML files. "<!--Line comment-->" Commented Mar 14, 2016 at 15:52

6 Answers 6

3

As mentioned above you can comment in XML just like this:

<!-- Comment -->

But in android studio you can very easily toggle comment just by selecting what you want to comment and then pressing:

CTRL + /

This not only for XML but also for your java code for example.

Sign up to request clarification or add additional context in comments.

Comments

1

It is indeed possible. I'm not sure if there is an accepted practice, but you can accomplish leaving a comment like this

<!-- comment goes here -->

5 Comments

Android Studio 1.5.1 seems to not like this: imgur.com/nVlww5a and as far as I can remember it never has.
@Timestretch - this actually does work, as long as you are not putting these comments within the definition of a single view. You can comment out whole views.
@KristyWelsh Can you elaborate?
@KristyWelsh Commenting out entire views works, but it is pretty crippling to only be able to do this. Is this a limitation of XML or Android Studio's interpretation of it?
@Timestretch - I think this is a limitation of XML.
1

Same as in all XML applications: Just use <!-- ... --> to comment.

Comments

0

Comments in XML aren't too tough. You have to do it like this:

For example

<!-- This is a comment -->

Please don't hesitate to ask for anymore help. The above should work in android studio.

Comments

0

If you are using a Mac then command is command(button which looks like Windows start button ) + / If you are on Windows then it is Cntrl + /

Try and see if it works

Comments

0

In Android Studio DOLPHIN version I have tried using the and the file does NOT like it. It produces errors when used. I don't know about XML files much, but this AndroidManifest.xml file does not like this. Any other tips that might work? This file is error free before the comment line is added.

picture of errors

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.