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

时间:2015-02-11 17:04:23

标签: android alertdialog android-alertdialog

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)是什么意思?什么表达式resid> = 0x0100000检查?为什么渣油应该大于0x01000000到“实际资源ID的开始”?

1 个答案:

答案 0 :(得分:5)

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

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

所以0x01000000是实际资源ID的开始"。

见上面的评论" uint32_t id;" " struct ResTable_package"在android frameworks source file

" 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;
};