Android开发,XML文件注释方法

        android在很多地方都采用XML文件进行配置工程相关参数,如布局,这点类似于Qt。

一、注释方法。

        android的XML文件注释的方法一般如下:

<!-- 注释内容 -->
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.debugtool">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ico"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.DebugTool">

        <!-- 寞水 -->

        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

    <uses-permission android:name="android.permission.INTERNET" />

</manifest>

 

二、注意事项。

        在进行注释过程中,发有时不能进行注释,如下:

            <Button
                <!-- 寞水 -->
                android:id="@+id/button"
                android:layout_width="50dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:paddingLeft="0dp"
                android:paddingRight="0dp"
                android:text="IP"
                app:backgroundTint="#009688" />
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.debugtool">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ico"

        <!-- 寞水 -->

        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.DebugTool">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

    <uses-permission android:name="android.permission.INTERNET" />

</manifest>

        在XML中,“<name />”是一个最小的组成单元,它中间不能再包含其他任何“< >”的代码,所以在<Button />中间注释会报语法错误。而在“<application></<application>”中的“android:theme="@style/Theme.DebugTool">”后能够加注释,在其前面不能加注释,这是因为有一个单独的“>”符号,个人理解“>”符号前的内容为“<application></<application>”本身属性的最小单元的描述。

おすすめ

転載: blog.csdn.net/weixin_43782998/article/details/120237056