开发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"));

 

相关文章:

  • 2021-06-21
  • 2021-09-19
  • 2021-04-29
  • 2021-10-03
  • 2021-12-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-25
  • 2021-10-23
  • 2022-12-23
  • 2021-12-04
相关资源
相似解决方案