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

最近在作一個android player項目,想要默認使用android的internal資源,好比: java

com.android.internal.R.layout.media_controller
可是,直接使用會報編譯錯誤:

com.android.internal.R does not exist android

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

可是能夠經過其餘的方式來訪問,以下: git

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, github

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

而上述name/defType/defPackage如何獲得?能夠從源碼中得到相應的信息  this

相關文章
相關標籤/搜索