欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

通过id获取到命名

程序员文章站 2022-07-12 19:36:04
...
写道
Resources类中的这个方法可以通过id获取到命名,不过获取到的命名格式是 package:type/entry;
一般获得context后,用getResources().getResourceName(int id), 返回字符串

/**
* Return the full name for a given resource identifier. This name is
* a single string of the form "package:type/entry".
*
* @param resid The resource identifier whose name is to be retrieved.
*
* @return A string holding the name of the resource.
*
* @throws NotFoundException Throws NotFoundException if the given ID does not exist.
*
* @see #getResourcePackageName
* @see #getResourceTypeName
* @see #getResourceEntryName
*/
public String getResourceName(@AnyRes int resid) throws NotFoundException {
return mResourcesImpl.getResourceName(resid);
}