public static void setWidgetTheme(Context context, View view, String resName){ String pkgName = PreferenceManager.getDefaultSharedPreferences(context).getString(PREF_KEY_THEME_PACKAGE, context.getPackageName()); Resources themeResources = null ; try { themeResources = context.getPackageManager().getResourcesForApplication(pkgName); } catch (NameNotFoundException e) { e.printStackTrace(); } if (themeResources == null ){ try { pkgName = context.getPackageName(); themeResources = context.getPackageManager().getResourcesForApplication(pkgName); saveThemePackageName(context, pkgName); } catch (NameNotFoundException e) { e.printStackTrace(); } } if (themeResources == null ){ return ; } try { int resource_id = themeResources.getIdentifier(resName, "drawable" , pkgName); if (resource_id != 0 ){ Drawable drawable = themeResources.getDrawable(resource_id); if (view != null ){ view.setBackgroundDrawable(drawable); } else { Log.w(TAG, "View is null! resName = " + resName); } } } catch (Resources.NotFoundException e){ e.printStackTrace(); } }

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. 全球开发者报告:1100万开发人员积极使用 J
  2. JavaScript测试教程–part 4:模拟 API 调
  3. 服务端指南 数据存储篇 | MySQL(08) 分库与
  4. 常用数据结构的 JavaScript 实现代码[每
  5. JavaScript 测试教程–part 3:测试 props,
  6. 服务端指南 数据存储篇 | MySQL(09) 分库与
  7. 迈向 serverless 开发的第一步[每日前端
  8. android中导入低版本project
  9. package.json 详解[每日前端夜话0xEF]
  10. 聊聊 Redis 使用场景