Skip to content

Commit e43d6e3

Browse files
salmon-21claude
andcommitted
Fixed: Improve dark mode support for settings and shared activities
Replace hardcoded light-only colors with theme attributes so that SettingsActivity, ReportActivity, TextIOActivity, and message dialogs follow the system dark mode setting. Also update toolbar styling to use a neutral surface color instead of the red brand color, and wrap the toolbar in AppBarLayout for proper elevation shadow. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3f0dec3 commit e43d6e3

File tree

7 files changed

+36
-16
lines changed

7 files changed

+36
-16
lines changed

termux-shared/src/main/java/com/termux/shared/activities/TextIOActivity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
import androidx.appcompat.app.AppCompatActivity;
2525
import androidx.appcompat.widget.Toolbar;
2626

27+
import com.termux.shared.activity.media.AppCompatActivityUtils;
2728
import com.termux.shared.interact.ShareUtils;
2829
import com.termux.shared.logger.Logger;
2930
import com.termux.shared.R;
31+
import com.termux.shared.theme.NightMode;
3032
import com.termux.shared.models.TextIOInfo;
3133
import com.termux.shared.view.KeyboardUtils;
3234

@@ -63,6 +65,8 @@ protected void onCreate(Bundle savedInstanceState) {
6365
super.onCreate(savedInstanceState);
6466
Logger.logVerbose(LOG_TAG, "onCreate");
6567

68+
AppCompatActivityUtils.setNightMode(this, NightMode.getAppNightMode().getName(), true);
69+
6670
setContentView(R.layout.activity_text_io);
6771

6872
mTextIOLabel = findViewById(R.id.text_io_label);

termux-shared/src/main/java/com/termux/shared/interact/MessageDialogUtils.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import android.app.AlertDialog;
55
import android.content.Context;
66
import android.content.DialogInterface;
7-
import android.graphics.Color;
7+
import android.content.res.TypedArray;
88
import android.view.LayoutInflater;
99
import android.view.View;
1010
import android.widget.Button;
@@ -51,7 +51,7 @@ public static void showMessage(Context context, String titleText, String message
5151
final DialogInterface.OnClickListener onNegativeButton,
5252
final DialogInterface.OnDismissListener onDismiss) {
5353

54-
AlertDialog.Builder builder = new AlertDialog.Builder(context, androidx.appcompat.R.style.Theme_AppCompat_Light_Dialog);
54+
AlertDialog.Builder builder = new AlertDialog.Builder(context, androidx.appcompat.R.style.Theme_AppCompat_DayNight_Dialog);
5555

5656
LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
5757
View view = inflater.inflate(R.layout.dialog_show_message, null);
@@ -81,12 +81,17 @@ public static void showMessage(Context context, String titleText, String message
8181

8282
dialog.setOnShowListener(dialogInterface -> {
8383
Logger.logError("dialog");
84+
int[] attrs = new int[] { android.R.attr.textColorPrimary };
85+
TypedArray ta = context.obtainStyledAttributes(attrs);
86+
int textColor = ta.getColor(0, 0xFF000000);
87+
ta.recycle();
88+
8489
Button button = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
8590
if (button != null)
86-
button.setTextColor(Color.BLACK);
91+
button.setTextColor(textColor);
8792
button = dialog.getButton(AlertDialog.BUTTON_NEGATIVE);
8893
if (button != null)
89-
button.setTextColor(Color.BLACK);
94+
button.setTextColor(textColor);
9095
});
9196

9297
dialog.show();

termux-shared/src/main/res/layout/dialog_show_message.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
android:layout_width="wrap_content"
1818
android:layout_height="wrap_content"
1919
android:textAppearance="@style/TextAppearance.AppCompat.Title"
20-
android:textColor="@android:color/white"/>
20+
android:textColor="?android:attr/textColorPrimaryInverse"/>
2121
</LinearLayout>
2222

2323
<ScrollView
@@ -37,8 +37,8 @@
3737
android:layout_height="wrap_content"
3838
android:autoLink="web|email"
3939
android:textSize="14sp"
40-
android:textColor="@android:color/tab_indicator_text"
41-
android:textColorLink="@android:color/black"/>
40+
android:textColor="?android:attr/textColorPrimary"
41+
android:textColorLink="?android:attr/textColorLink"/>
4242
</LinearLayout>
4343
</ScrollView>
4444

termux-shared/src/main/res/layout/partial_primary_toolbar.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<com.google.android.material.appbar.AppBarLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
34
xmlns:app="http://schemas.android.com/apk/res-auto"
45
android:id="@+id/toolbar_container"
56
android:layout_width="match_parent"
6-
android:layout_height="wrap_content"
7-
android:orientation="vertical">
7+
android:layout_height="wrap_content">
88

99
<androidx.appcompat.widget.Toolbar
1010
android:id="@+id/toolbar"
@@ -19,4 +19,4 @@
1919
app:subtitleTextAppearance="@style/TextAppearance.Widget.BaseToolbar.Subtitle">
2020
</androidx.appcompat.widget.Toolbar>
2121

22-
</LinearLayout>
22+
</com.google.android.material.appbar.AppBarLayout>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<color name="background_markdown_code_inline">#1FFFFFFF</color>
4+
<color name="background_markdown_code_block">#0FFFFFFF</color>
5+
</resources>

termux-shared/src/main/res/values-night/themes.xml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@
99
-->
1010
<style name="Theme.BaseActivity.DayNight.DarkActionBar" parent="Theme.MaterialComponents">
1111
<!-- Primary brand color. -->
12-
<item name="colorPrimary">@color/red_400</item>
13-
<item name="colorPrimaryVariant">@color/red_800</item>
14-
<item name="colorOnPrimary">@color/black</item>
12+
<item name="colorPrimary">@color/grey_900</item>
13+
<item name="colorPrimaryVariant">@color/black</item>
14+
<item name="colorOnPrimary">@color/white</item>
1515

1616
<!-- Secondary brand color. -->
1717
<item name="colorSecondary">@color/grey_400</item>
1818
<item name="colorSecondaryVariant">@color/grey_500</item>
1919
<item name="colorOnSecondary">@color/black</item>
2020

21+
<!-- Accent color for widgets (switches, checkboxes, etc.). -->
22+
<item name="colorAccent">@color/red_400</item>
23+
2124
<!-- Status bar color. -->
2225
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
2326
<item name="colorPrimaryDark" tools:targetApi="l">?attr/colorPrimary</item>

termux-shared/src/main/res/values/themes.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@
2020
<item name="colorSecondaryVariant">@color/black</item>
2121
<item name="colorOnSecondary">@color/white</item>
2222

23+
<!-- Toolbar / ActionBar background color. -->
24+
<item name="colorPrimaryDark" tools:targetApi="l">@color/white</item>
25+
2326
<!-- Status bar color. -->
24-
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
25-
<item name="colorPrimaryDark" tools:targetApi="l">?attr/colorPrimary</item>
27+
<item name="android:statusBarColor" tools:targetApi="l">@color/white</item>
28+
<item name="android:windowLightStatusBar" tools:targetApi="m">true</item>
2629

2730
<!-- Text color. -->
2831
<item name="android:textColorPrimary">@color/black</item>

0 commit comments

Comments
 (0)