本文介绍了我怎样才能获得的资源按名称(字符串),而不是整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如:
公共final类环R {
公共静态final类原料{
公共静态最终诠释尤里= 0x7f040000;
}
}
我怎样才能获得其名称的资源?如果不使用R.raw.yuri =(INT)
解决方案
getResources()则getIdentifier(尤里,原始,getPackageName())。
我发现这是非常缓慢的。我剥离出来我的整个项目做一些分析后,并使用 INT []
代替。
for example:
public final class R {
public static final class raw {
public static final int yuri=0x7f040000;
}
}
How can I get the resource by its name?Without using R.raw.yuri = (int)
解决方案
getResources().getIdentifier( "yuri" , "raw" , getPackageName() );
I found this to be extremely slow. I stripped it out of my whole project after doing some profiling and used int[]
instead.
这篇关于我怎样才能获得的资源按名称(字符串),而不是整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!