如何在AndroidStudio中注释掉xml中的行?

4

我在 AndroidManifest.xml 文件中有以下代码段,我想要注释掉其中的一行(用于快速测试)。通过选择 Android Studio 的注释功能,我得到了以下结果:

<application
    android:allowBackup="true"
    android:icon="@mipmap/myicon"
    android:label="@string/app_name"
    android:supportsRtl="true"
    <!--android:theme="@style/AppTheme"-->
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar" >

然而,这会造成编译错误:
Error:Element type "application" must be followed by either attribute specifications, ">" or "/>".

有没有一种简单的方法可以注释掉一行或多行代码,还是我应该打开外部文本编辑器并将原始的行复制粘贴到那个外部文本编辑器中?

5个回答

3
您可以注释掉标签之外的内容,例如:

您可以使用此方式进行注释:

<application
    android:allowBackup="true"
    android:icon="@mipmap/myicon"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar" >

 <!--android:theme="@style/AppTheme"-->

不在标签内部。


这似乎可以工作。虽然不是最优的,但最好将所有内容复制到另一个文件中。不知道为什么AndroidStudio不知道这个... - Alex

1

在XML中不可能添加注释,如果您想添加注释,则必须使用XML语法,并且语法是在标签开始或结束之前使用注释。


0

您不能在标签内添加注释。请参见this问题的答案。


0
XML不允许在标签内部添加注释。你只能将整个元素注释掉。

0

你需要将它放在外面。请参考:这里


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接