When you write your own tools into a. jar package, you sometimes need to refer to the resources in res, and you cannot package the resources together, but you can obtain resources dynamically through the reflection mechanism.
Especially when you define a tool to make it into a. jar package, pay particular attention to resource acquisition
1, packaged into a tool class
Packagecom.cp.utils;ImportAndroid.content.Context; Public classCpresourceutil { Public Static intGetlayoutid (Context paramcontext, String paramstring) {returnParamcontext.getresources (). Getidentifier (paramstring, "layout", Paramcontext.getpackagename ()); } Public Static intGetstringid (Context paramcontext, String paramstring) {returnParamcontext.getresources (). Getidentifier (paramstring, "string", Paramcontext.getpackagename ()); } Public Static intGetdrawableid (Context paramcontext, String paramstring) {returnparamcontext.getresources (). Getidentifier (Paramstring,"Drawable", Paramcontext.getpackagename ()); } Public Static intGetstyleid (Context paramcontext, String paramstring) {returnparamcontext.getresources (). Getidentifier (Paramstring,"Style", Paramcontext.getpackagename ()); } Public Static intgetId (Context paramcontext, String paramstring) {returnParamcontext.getresources (). Getidentifier (paramstring, "id", Paramcontext.getpackagename ()); } Public Static intGetcolorid (Context paramcontext, String paramstring) {returnparamcontext.getresources (). Getidentifier (Paramstring,"Color", Paramcontext.getpackagename ()); } Public Static intGetarrayid (Context paramcontext, String paramstring) {returnparamcontext.getresources (). Getidentifier (Paramstring,"Array", Paramcontext.getpackagename ()); } }
2. Access to resources
<name= "Version_update_schedule"> downloaded%1 $ s Please wait for & #8230; </ string >
String text=mcontext.getresources (). GetString (Cpresourceutil.getstringid (Mcontext, "Version_update_schedule"));
Version_update_schedule is a string file in the name
Get the resource ID through reflection in Android