AndroidChangeSkin icon indicating copy to clipboard operation
AndroidChangeSkin copied to clipboard

backgroud 为color时 报 NotFoundException: Resource ID #0x0

Open IAskWind opened this issue 8 years ago • 2 comments

页面设置: android:tag="skin:skin_colorPrimary:background" android:background="@color/skin_colorPrimary" 报错: No package identifier when getting value for resource number 0x00000000 ........................... at com.zhy.changeskin.attr.SkinAttrType$1.apply(SkinAttrType.java:23) 指向: Drawable drawable = getResourceManager().getDrawableByName(resName); 没有找到资源

IAskWind avatar Apr 25 '16 05:04 IAskWind

修改SkinAttrType 添加对color 的支持

 BACKGROUD("background") {
    @Override
    public void apply(View view, String resName) {
        Drawable drawable = getResourceManager().getDrawableByName(resName);
        // TODO ZHL 添加一种background 设置成color的情况
        if (null!=drawable){
            view.setBackgroundDrawable(drawable);
        }else{
            int color = getResourceManager().getColor(resName);
            if(color==-1)
                return ;
            view.setBackgroundColor(color);
        }
    }
}

yilylong avatar Apr 27 '16 08:04 yilylong

"No package identifier when getting value for resource number 0x00000000" - This is warning when id resource equal 0. If you want not to out warning you can check id resource, for example:

public Drawable getDrawableByName(String name) {
    try {
        int id = mResources.getIdentifier(name, "drawable", mPluginPackageName);
        return id == 0 ? getDrawable(name) : mResources.getDrawable(id);
    } catch (Exception e) {
        return getDrawable(name);
    }
}

hoangsondev avatar May 19 '16 03:05 hoangsondev