私はアンドロイドで簡単なメモウィジェットを作成しました。ウィジェットの色が日中赤から夜に黒に変わる夜間モード機能を追加しました。私はアプリは一日の時間に基づいてウィジェットを変更するには、このコードを使用:ナイトモードがオンになる一度夜間モードの更新ウィジェット
// Find Night Mode Automatically//
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO);
// Checks Whether app Is In Night Mode Or Not//
int currentNightMode = context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
// Checks All Scenarios//
switch (currentNightMode) {
// Night Mode Is Not Active, We're In Day Time//
case Configuration.UI_MODE_NIGHT_NO: {
// Instantiate Variable RemoteViews remoteViews/Directs Activity To GUI//
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.note_widget_ui);
// Initiate viewText Method//
viewText(context, remoteViews);
// Kill Code//
break;
}
// Night Mode Is Active, We're At Night!//
case Configuration.UI_MODE_NIGHT_YES: {
// Instantiate Variable RemoteViews remoteViews/Directs Activity To GUI//
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.note_widget_night_ui);
// Initiate viewText Method//
viewText(context, remoteViews);
// Kill Code//
break;
}
// We Don't Know What Mode We're In, Assume Notnight//
case Configuration.UI_MODE_NIGHT_UNDEFINED: {
// Instantiate Variable RemoteViews remoteViews/Directs Activity To GUI//
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.note_widget_ui);
// Initiate viewText Method//
viewText(context, remoteViews);
// Kill Code//
break;
}
}
は、どのように私は、ウィジェットがその色を更新するために、このコードを使用します。もう一つの例は、ノーバランチャーとGoogleバーウィジェットです。それはアンドロイドによって夜間モードが起動されると切り替わります。誰もこれを行う方法を知っていますか?
この[1](http://blog.nkdroidsolutions.com/android-daynight-theme-example-using-appcompat-v23-2/)をご覧ください。 –
私の昼夜モードを変更する活動は良いです。私のホーム画面上のウィジェットを赤から黒に変えて問題を解決しています。私は一度だけ夜や日が来ると、ウィジェットがそれを更新する方法を知らない – Jordan
あなたは、色のxmlとパブリックスタイルのクラスを作り直しましたか? –