首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

Flutter黑科技一键打开资源文件

在Flutter开发过程中,使用资源文件是必不可少的,当项目的结构越来越复杂,引入的资源文件越来越多,大家有没有遇到这样的一个问题,如果我在代码中写了这样的一个文件路径assets/image/xxx/xxx.png的时候,当需要查看这个文件时,就会发现我们要一步一步的在自己的项目下找到assets文件夹,然后找到image,然后找到xxx...,这一个步骤浪费了大量的时间,并且每次查看就得浪费一次,如果有这样的一个能根据字符串一键打开这个图片该多好啊!,不用如果,现在就有了,只需要在Android Studio 查找插件FlutterQuickLocateAsset安装即可,so easy! 欢迎体验和评分!并且谢谢您的支持!

02

Resources和AssetManager创建过程

到这里AssetManager创建完毕。然后设置相关的路径 AssetManager assets = new AssetManager(); // resDir can be null if the 'android' package is creating a new Resources object. // This is fine, since each AssetManager automatically loads the 'android' package // already. if (resDir != null) { if (assets.addAssetPath(resDir) == 0) { return null; } } if (splitResDirs != null) { for (String splitResDir : splitResDirs) { if (assets.addAssetPath(splitResDir) == 0) { return null; } } } if (overlayDirs != null) { for (String idmapPath : overlayDirs) { assets.addOverlayPath(idmapPath); } } if (libDirs != null) { for (String libDir : libDirs) { if (libDir.endsWith(".apk")) { // Avoid opening files we know do not have resources, // like code-only .jar files. if (assets.addAssetPath(libDir) == 0) { Log.w(TAG, "Asset path '" + libDir + "' does not exist or contains no resources."); } } } } 接着就创建Resource对象 r = new Resources(assets, dm, config, compatInfo); 这里看到AssetManager保存到了Resources对象中。接着进入到Resources的构造方法中 public Resources(AssetManager assets, DisplayMetrics metrics, Configuration config, CompatibilityInfo compatInfo) { mAssets = assets; mMetrics.setToDefaults(); if (compatInfo != null) { mCompatibilityInfo = compatInfo; } updateConfiguration(config, metrics); assets.ensureStringBlocks(); } 最后进入到updateConfiguration(Configuration config, DisplayMetrics metrics, CompatibilityInfo compat) mAssets.setConfiguration(mConfiguration.mcc, mConfiguration.mnc, locale, mConfiguration.orientation, mConfiguration.touchscreen, mConfiguration.densityDpi, mConfiguration.keyboard, keyboardHidden, mConfiguration.navigation, width, height, mConfiguration.smallestScreenWidthDp, mConfiguration.screenWidthDp, mConfiguration.screenHeightDp, mConfiguration.screenLayout, mConfiguration.uiMode, Build.VERSION.RESOURCES

05

扫码

添加站长 进交流群

领取专属 10元无门槛券

手把手带您无忧上云

扫码加入开发者社群

相关资讯

热门标签

活动推荐

    运营活动

    活动名称
    广告关闭
    领券