Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions android/src/toga_android/widgets/detailedlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,37 @@
from android.app import AlertDialog
from android.content import DialogInterface
from android.graphics import Color, Rect
from android.util import TypedValue
from android.view import Gravity, View
from android.widget import ImageView, LinearLayout, RelativeLayout, ScrollView, TextView
from java import dynamic_proxy

from .base import Widget


def _resolve_theme_color(view, attr_id, fallback):
tv = TypedValue()
ctx = view.getContext()
th = ctx.getTheme()
if th.resolveAttribute(attr_id, tv, True):
if tv.resourceId:
try:
# API 23+ path used on modern emulators
return ctx.getColor(tv.resourceId)
except Exception: # pragma: no cover - emulator hits API 23+ path
try:
# Legacy path (pre-23); not exercised in CI emulators
return ctx.getResources().getColor(
tv.resourceId
) # pragma: no cover
except Exception: # pragma: no cover - double-fallback not hit
pass # pragma: no cover
# Inline color int (ARGB) stored in tv.data (rare on textColor attrs)
if getattr(tv, "data", 0): # pragma: no cover
return tv.data # pragma: no cover
return fallback # pragma: no cover


try:
from androidx.swiperefreshlayout.widget import SwipeRefreshLayout
except ImportError: # pragma: no cover
Expand All @@ -16,9 +43,6 @@
SwipeRefreshLayout = None


from .base import Widget


class DetailedListOnClickListener(dynamic_proxy(View.OnClickListener)):
def __init__(self, impl, row_number):
super().__init__()
Expand Down Expand Up @@ -181,14 +205,14 @@ def get_string(value):
top_text.setText(get_string(title))
top_text.setTextSize(20.0)
top_text.setTextColor(
self._native_activity.getResources().getColor(R.color.black)
_resolve_theme_color(top_text, R.attr.textColorPrimary, Color.BLACK)
)
bottom_text = TextView(self._native_activity)
bottom_text.setTextColor(
self._native_activity.getResources().getColor(R.color.black)
)
bottom_text.setText(get_string(subtitle))
bottom_text.setTextSize(16.0)
bottom_text.setTextColor(
_resolve_theme_color(bottom_text, R.attr.textColorSecondary, Color.BLACK)
)
top_text_params = LinearLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.MATCH_PARENT,
Expand Down
1 change: 1 addition & 0 deletions changes/3751.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Android: DetailedList now uses theme-resolved text colors (Primary/Secondary) instead of hard-coded black, fixing unreadable text in dark mode.
Loading