AlertDialog源代码中的resid >= 0x0100000是什么意思?

3

AlertDialog源代码有以下方法:

static int resolveDialogTheme(Context context, int resid) {
    if (resid == THEME_TRADITIONAL) {
        return com.android.internal.R.style.Theme_Dialog_Alert;
    } else if (resid == THEME_HOLO_DARK) {
        return com.android.internal.R.style.Theme_Holo_Dialog_Alert;
    } else if (resid == THEME_HOLO_LIGHT) {
        return com.android.internal.R.style.Theme_Holo_Light_Dialog_Alert;
    } else if (resid == THEME_DEVICE_DEFAULT_DARK) {
        return com.android.internal.R.style.Theme_DeviceDefault_Dialog_Alert;
    } else if (resid == THEME_DEVICE_DEFAULT_LIGHT) {
        return com.android.internal.R.style.Theme_DeviceDefault_Light_Dialog_Alert;
    } else if (resid >= 0x01000000) {   // start of real resource IDs.
        return resid;
    } else {
        TypedValue outValue = new TypedValue();
        context.getTheme().resolveAttribute(com.android.internal.R.attr.alertDialogTheme,
                    outValue, true);
        return outValue.resourceId;
    }
}

0x01000000代表2的24次方,那么它在IT技术中的含义是什么呢?而 resid >= 0x0100000 这个表达式的作用是什么?为什么resid应该大于0x01000000才能“开始真正的资源ID”?

1个回答

5

Android资源ID的第24-31位是包ID。

包ID从1开始,0表示这不是一个基础包。

因此,0x01000000是“真实资源ID的起点”。

请参见android框架源文件中“struct ResTable_package”的“uint32_t id;”上面的注释。

“struct ResTable_package”定义如下:

/**
 * A collection of resource data types within a package.  Followed by
 * one or more ResTable_type and ResTable_typeSpec structures containing the
 * entry values for each resource type.
 */
struct ResTable_package
{
    struct ResChunk_header header;

    // If this is a base package, its ID.  Package IDs start
    // at 1 (corresponding to the value of the package bits in a
    // resource identifier).  0 means this is not a base package.
    uint32_t id;

    // Actual name of this package, \0-terminated.
    char16_t name[128];

    // Offset to a ResStringPool_header defining the resource
    // type symbol table.  If zero, this package is inheriting from
    // another base package (overriding specific values in it).
    uint32_t typeStrings;

    // Last index into typeStrings that is for public use by others.
    uint32_t lastPublicType;

    // Offset to a ResStringPool_header defining the resource
    // key symbol table.  If zero, this package is inheriting from
    // another base package (overriding specific values in it).
    uint32_t keyStrings;

    // Last index into keyStrings that is for public use by others.
    uint32_t lastPublicKey;
};

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