How to access the resource of com.android.internal.R
最近在做一个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)
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。