Comments (4)
我之前写了个工具类,就是通过包名,反射获取资源id,value,这个你要么,要的话我回头整理下发你,你塞里吧
哈哈,你发下,我看下具体实现什么功能,有必要的话可以放进去,目前有获取资源 id 的 ResourceUtils getIdentifier 方法
/**
* 获取资源 id
* @param resName 资源名
* @param defType 资源类型
* @param packageName 应用包名
* @return 资源 id
*/
public static int getIdentifier(final String resName, final String defType, final String packageName) {
try {
return DevUtils.getContext().getResources().getIdentifier(resName, defType, packageName);
} catch (Exception e) {
LogPrintUtils.eTag(TAG, e, "getIdentifier - " + resName + " " + defType + ": " + packageName);
}
return 0;
}
from devutils.
稍微晚几天,在外地
from devutils.
public class ResourcesUtils {
private AssetManager mAsset = AssetManager.class.newInstance();
private Method addAssetPath = mAsset.getClass().getMethod("addAssetPath", String.class);
private Context context;
private Resources pluginResources;
private String packageName;
public ResourcesUtils() throws InstantiationException, IllegalAccessException, NoSuchMethodException {
}
public void init(Context context, String fileUrl) throws InvocationTargetException, IllegalAccessException {
this.context = context;
pluginResources = new Resources(mAsset, context.getResources().getDisplayMetrics(), context.getResources().getConfiguration());
//TODO 此处需要先判断 fileUrl 是否有文件
addAssetPath.invoke(mAsset, fileUrl);
PackageInfo packageArchiveInfo = context.getPackageManager().getPackageArchiveInfo(
fileUrl,
PackageManager.GET_ACTIVITIES
);
packageName = packageArchiveInfo.packageName;
}
public String getString(String stringName){
int stringId = pluginResources.getIdentifier(stringName, "string", packageName);
return pluginResources.getString(stringId);
}
}
from devutils.
已经实现了 ResourcePluginUtils.java,过几天再发个版本,上次的日历工具类:CalendarUtils.java
from devutils.
Related Issues (20)
- 关联库出错 HOT 3
- 能否出个android Q的文件存储操作等的适配 HOT 1
- 建议加一个 WorkManager 封装工具类 HOT 1
- 发现demo在使用DevEnvironment过程中会出现如下问题 ,华为8.10 10.0.0 都有这个报错信息 HOT 1
- DevEnvironment 的DevEnvironmentActivity 界面显示错误 HOT 1
- 请问坐标系工具类里面通过两点的坐标系计算距离这个功能,是在哪个坐标体系下进行计算的?谷歌的?还是火星坐标系?还是百度坐标系 HOT 1
- 请问坐标系工具类里面通过两点的坐标系计算距离这个功能,是在哪个坐标体系下进行计算的?谷歌的?还是火星坐标系?还是百度坐标系?
- 截图工具类 HOT 2
- 建议加上获取可运行app列表的API HOT 1
- DateUtils.isInTimeHHmmss("7:00","7:00") HOT 4
- 版本适配库 HOT 24
- ava.lang.Exception: Toast callstack! HOT 2
- 狗都不用
- AlarmUtils.java HOT 2
- DEV工具类,是否有清除缓存和计算缓存大小的方法? HOT 2
- AppUtils HOT 2
- GsonUtils HOT 1
- 电池电量信息 HOT 1
- error: resource android:color/system_neutral2_500 not found
- JSON to Code报错问题 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from devutils.