開發APP過程中可能要有中文模式和英文模式,切換后控件要隨着進行更改,以下代碼可以很好的實現:
public static int getResourcesId(Context context, String resName, String resTpye) { String language = Locale.getDefault().getLanguage(); String resString = resName + "_eng"; if (language.contains("zh")) { resString = resName + "_cn"; } else { resString = resName + "_eng"; } return context.getResources().getIdentifier(resString, resTpye, context.getPackageName()); }
再調用以上方法
mSharePictureToBack.setBackgroundResource(Utils.getResourcesId(MyApplication
.getAppContext(), "share_transmission_blue_back_style", "drawable"));