android设置系统语言,字体大小,字体样式导致widget控件失效
来源:互联网 发布:淘宝售后说明 编辑:程序博客网 时间:2024/05/20 08:42
在setting中设置系统的字体大小,样式,以及系统语言等等会对widget产生影响,造成widget控件失效。
由于在setting中设置系统的字体大小,样式,以及系统语言等等系统发出 android.appwidget.action.APPWIDGET_UPDATE的 广播,
此时的解决方案如下:
自定义的MyAppWidgetProvider继承于AppWidgetProvider,监听android.appwidget.action.APPWIDGET_UPDATE广播
在该类的onReceive()回调方法中,重新注册控件监听。
private void initListener(Context context){AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, MyAppWidgetProvider.class));RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget_myprovider);Intent intent;PendingIntent pendingIntent;ComponentName serviceName = new ComponentName(context, MyAppWidgetService.class);/** 刷新按钮 */intent = new Intent(MyAppWidgetService.MSG_REFRESH);intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);intent.setComponent(serviceName);pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);views.setOnClickPendingIntent(R.id.appwidget_refresh_new, pendingIntent);/** 前一页 */intent = new Intent(MyAppWidgetService.MSG_PRE);intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);intent.setComponent(serviceName);pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);views.setOnClickPendingIntent(R.id.appwidget_last, pendingIntent);/** 后一页 */intent = new Intent(MyAppWidgetService.MSG_NEXT);intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);intent.setComponent(serviceName);pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);views.setOnClickPendingIntent(R.id.appwidget_next, pendingIntent);appWidgetManager.updateAppWidget(appWidgetIds, views);}
@Overridepublic void onReceive(Context context, Intent intent) {super.onReceive(context, intent);initListener(context);}
- android设置系统语言,字体大小,字体样式导致widget控件失效
- 关于Android切换系统字体大小和字体样式导致App崩溃或者界面错乱的问题
- 给Android Studio设置代码字体大小与界面字体样式
- Android设置App字体不跟随系统字体大小变化
- 设置一个Label控件上文字的字体样式和字体大小随机的代码.
- 设置一个Label控件上文字的字体样式和字体大小随机的代码
- VC设置控件的字体颜色和背景颜色和字体大小和样式
- CSS样式字体设置失效,呈现乱码
- android设置字体样式
- android设置字体样式
- 为android系统控件设置样式
- Android自定义控件字体大小设置。
- android 中如何设置控件的字体和背景样式
- Android Toast设置字体大小字体颜色
- Android 自定义字体样式 及系统默认字体样式 的设置
- android 字体大小,样式 ,像素的设置
- android系统设置里的字体大小导致的布局混乱问题
- [Android] 字体使用dp单位避免设置系统字体大小对排版的影响
- Javascript中setTimeout()和clearTimeout()还有setInterval()用法
- 理解JavaScript中的arguments,callee,caller,apply 和call
- oracle中exp,imp的使用详解
- 彻底卸载风行播放器
- hbase数据的导入与导出
- android设置系统语言,字体大小,字体样式导致widget控件失效
- socket
- linux下第一个java程序
- Windows下常用系统宏,如文件名,行号,日期
- windows平台手动编译pcre
- FAT32与FAT16 有何区别
- Java多线程对耗时方法的同步问题
- CAS异常之context[]startup failed due to previous errors
- 设置mysql的interactive_timeout和wait_timeout的值