码迷,mamicode.com
首页 > 移动开发 > 详细

How to access the resource of com.android.internal.R

时间:2015-05-29 01:01:33      阅读:319      评论:0      收藏:0      [点我收藏+]

标签:

最近在做一个android player项目,想要默认使用android的internal资源,比如:

com.android.internal.R.layout.media_controller



但是,直接使用会报编译错误:

com.android.internal.R does not exist

You cannot import the internal android class, as the internal.R class isn‘t visible.

但是可以通过其他的方式来访问,如下:

int mediaControllerId = Resources.getSystem().getIdentifier("media_controller", "layout", "android");

View layout = ((LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(mediaControllerId, this);



同理,可以访问:

mPrevButton = (ImageButton) layout.findViewById(Resources.getSystem().getIdentifier("prev","id", "android"));
mProgress = (ProgressBar) layout.findViewById(Resources.getSystem().getIdentifier("mediacontroller_progress","id", "android"));
mPauseButton = (ImageButton) layout.findViewById(Resources.getSystem().getIdentifier("pause","id", "android"));

getIdentifier的使用方式如下,会返回name对应的id,

Resources.getSystem().getIdentifier(name, defType, defPackage)



而上述name/defType/defPackage如何得到?可以从源码中获得相应的信息  http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.2.2_r1/android/widget/MediaController.java

How to access the resource of com.android.internal.R

标签:

原文地址:http://my.oschina.net/jerikc/blog/421772

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!