How can I set the theme change in the widget when the theme change is made in my Android application?
I tried such a method, but I did not get any results.
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
}
}
Try updating the widget when the theme in your app changes in your MainActivity or the activity the theme change gets notified in:
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)
And keep the code that you provided in your question the same. Tell me if it works :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With