Android 小部件主题更改
Android Wigdet Theme Change
当在我的 Android 应用程序中进行主题更改时,如何在小部件中设置主题更改?
我尝试过这样的方法,但没有得到任何结果。
int themeMode = mContext.getSharedPreferences("DH_MODE", Context.MODE_PRIVATE).getInt("DH_MODE", 0);
switch (themeMode){
case 0: {
// Gündüz modu
rv.setImageViewResource(R.id.img_flame, R.drawable.evening_logo);
rv.setTextViewText(R.id.txt_title," Gündüz modu");
rv.setTextColor(R.id.txt_title, Color.parseColor("#000000"));//siyah
break;
}
case 1: {
//Gece modu
rv.setImageViewResource(R.id.img_flame, R.drawable.evening_logo); // logolar da değişecekse diye imageview i de ekledim
rv.setTextViewText(R.id.txt_title," Gece modu");
rv.setTextColor(R.id.txt_title, Color.parseColor("#ffffff"));//beyaz
break;
}
case 2: {
//Gün batımı modu
rv.setImageViewResource(R.id.img_flame, R.drawable.evening_logo);
rv.setTextViewText(R.id.txt_title," gün batımı modu ");
rv.setTextColor(R.id.txt_title, Color.parseColor("#ffffff"));//beyaz
break;
}
case 3:{
rv.setImageViewResource(R.id.img_flame, R.drawable.evening_logo);
rv.setTextViewText(R.id.txt_title," akşam modu");
rv.setTextColor(R.id.txt_title, Color.parseColor("#ffffff"));//beyaz
}
}
当您的应用中的主题在您的 MainActivity 中更改时尝试更新小部件,或者 activity 主题更改在以下位置收到通知:
val widgetManagerObj = AppWidgetManager.getInstance(applicationContext)
val appWidgetIdArr = widgetManagerObj.getAppWidgetIds(ComponentName(applicationContext, YourWidgetProvider::class.java))
val refreshIntentObj = Intent(applicationContext, YourWidgetProvider::class.java)
refreshIntentObj.action = STATUS_ACTION
refreshIntentObj.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIdArr)
sendBroadcast(refreshIntentObj)
并保持您在问题中提供的代码不变。告诉我它是否有效:)
当在我的 Android 应用程序中进行主题更改时,如何在小部件中设置主题更改?
我尝试过这样的方法,但没有得到任何结果。
int themeMode = mContext.getSharedPreferences("DH_MODE", Context.MODE_PRIVATE).getInt("DH_MODE", 0);
switch (themeMode){
case 0: {
// Gündüz modu
rv.setImageViewResource(R.id.img_flame, R.drawable.evening_logo);
rv.setTextViewText(R.id.txt_title," Gündüz modu");
rv.setTextColor(R.id.txt_title, Color.parseColor("#000000"));//siyah
break;
}
case 1: {
//Gece modu
rv.setImageViewResource(R.id.img_flame, R.drawable.evening_logo); // logolar da değişecekse diye imageview i de ekledim
rv.setTextViewText(R.id.txt_title," Gece modu");
rv.setTextColor(R.id.txt_title, Color.parseColor("#ffffff"));//beyaz
break;
}
case 2: {
//Gün batımı modu
rv.setImageViewResource(R.id.img_flame, R.drawable.evening_logo);
rv.setTextViewText(R.id.txt_title," gün batımı modu ");
rv.setTextColor(R.id.txt_title, Color.parseColor("#ffffff"));//beyaz
break;
}
case 3:{
rv.setImageViewResource(R.id.img_flame, R.drawable.evening_logo);
rv.setTextViewText(R.id.txt_title," akşam modu");
rv.setTextColor(R.id.txt_title, Color.parseColor("#ffffff"));//beyaz
}
}
当您的应用中的主题在您的 MainActivity 中更改时尝试更新小部件,或者 activity 主题更改在以下位置收到通知:
val widgetManagerObj = AppWidgetManager.getInstance(applicationContext)
val appWidgetIdArr = widgetManagerObj.getAppWidgetIds(ComponentName(applicationContext, YourWidgetProvider::class.java))
val refreshIntentObj = Intent(applicationContext, YourWidgetProvider::class.java)
refreshIntentObj.action = STATUS_ACTION
refreshIntentObj.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIdArr)
sendBroadcast(refreshIntentObj)
并保持您在问题中提供的代码不变。告诉我它是否有效:)