- 注册时间
- 2013-4-19
- 最后登录
- 2024-9-26
- 阅读权限
- 200
- 积分
- 6404
- 精华
- 0
- 帖子
- 640
|
转载请注明:www.asysbang.com
在写android应用的资源文件时,有时写的格式是不一样的
如:
android:paddingLeft="@*android:dimen/preference_item_padding_side"
android:paddingRight="?android:attr/scrollbarSize"
android:background="?android:attr/selectableItemBackground"
不同的写法,会有不同的意思?那么android是如何解析这个写法的?
还有:
android:background="@null" ------ null 必须小写
android:baselineAligned="TRUE" ---- TRUE 大小写都可以
为什么有些必须小写,有些大小写都可以?
下面只是一个初步的探索,等有时间再具体深入
frameworks/base/libs/androidfw/ResourceTypes.cpp +4059 --------- android不同版本文件路径有所改动,这个是4.2的,4.0的在framework/base/libs/utils/ResourceTypes.cpp
bool ResTable::stringToValue( 函数负责解析
4140 if (*s == '@') {
4141 outValue->dataType = outValue->TYPE_REFERENCE;
4142
4143 // Note: we don't check attrType here because the reference can
4144 // be to any other type; we just need to count on the client making
4145 // sure the referenced type is correct.
4146
4147 //printf("Looking up ref: %s\n", String8(s, len).string());
4148
4149 // It's a reference!
4150 if (len == 5 && s[1]=='n' && s[2]=='u' && s[3]=='l' && s[4]=='l') {
4151 outValue->data = 0;
4152 return true;
4153 } else {
4154 bool createIfNotFound = false;
4155 const char16_t* resourceRefName;
4156 int resourceNameLen;
4157 if (len > 2 && s[1] == '+') {
4158 createIfNotFound = true;
4159 resourceRefName = s + 2;
4160 resourceNameLen = len - 2;
4161 } else if (len > 2 && s[1] == '*') {
4162 enforcePrivate = false;
4163 resourceRefName = s + 2;
4164 resourceNameLen = len - 2;
4165 } else {
4166 createIfNotFound = false;
4167 resourceRefName = s + 1;
4168 resourceNameLen = len - 1;
4169 }
4234 if (*s == '#') {
4235 // It's a color! Convert to an integer of the form 0xaarrggbb.
4236 uint32_t color = 0;
4237 bool error = false;
4310 if (*s == '?') {
4311 outValue->dataType = outValue->TYPE_ATTRIBUTE;
4312
4313 // Note: we don't check attrType here because the reference can
4314 // be to any other type; we just need to count on the client making
4315 // sure the referenced type is correct.
4316
4317 //printf("Looking up attr: %s\n", String8(s, len).string());
4318
4319 static const String16 attr16("attr");
4320 String16 package, type, name;
4433 if (len == 4) {
4434 if ((s[0] == 't' || s[0] == 'T') &&
4435 (s[1] == 'r' || s[1] == 'R') &&
4436 (s[2] == 'u' || s[2] == 'U') &&
4437 (s[3] == 'e' || s[3] == 'E')) {
4438 if ((attrType&ResTable_map::TYPE_BOOLEAN) == 0) {
4439 if (!canStringCoerce) {
4440 if (accessor != NULL) {
4441 accessor->reportError(accessorCookie, "Boolean types not allowed");
4442 }
4443 return false;
4444 }
4445 } else {
4446 outValue->dataType = outValue->TYPE_INT_BOOLEAN;
4447 outValue->data = (uint32_t)-1;
4448 return true;
4449 }
4450 }
4451 }
4452
4453 if (len == 5) {
4454 if ((s[0] == 'f' || s[0] == 'F') &&
4455 (s[1] == 'a' || s[1] == 'A') &&
4456 (s[2] == 'l' || s[2] == 'L') &&
4457 (s[3] == 's' || s[3] == 'S') &&
4458 (s[4] == 'e' || s[4] == 'E')) {
PS :CM(CyanogenMod)的主题切换功能呢个就是在这个文件里面添加了lookupRedirectionMap函数,来实现主题资源的重定向的
CyanogenMod 官方的代码修改review地址
review.cyanogenmod.org/
|
|