From 3d3bd05efee0682533aef9727423adc7182780cf Mon Sep 17 00:00:00 2001 From: ekibun Date: Sun, 19 Apr 2020 18:42:21 +0800 Subject: [PATCH] tint sub popup menu --- .../main/java/soko/ekibun/bangumi/util/ResourceUtil.kt | 9 +++++++-- app/src/main/res/layout/item_calendar.xml | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/soko/ekibun/bangumi/util/ResourceUtil.kt b/app/src/main/java/soko/ekibun/bangumi/util/ResourceUtil.kt index a331247..c390bec 100644 --- a/app/src/main/java/soko/ekibun/bangumi/util/ResourceUtil.kt +++ b/app/src/main/java/soko/ekibun/bangumi/util/ResourceUtil.kt @@ -86,14 +86,19 @@ object ResourceUtil{ return typedValue } - fun checkMenu(context: Context, menu: Menu, isChecked: (MenuItem) -> Boolean) { + fun checkMenu(context: Context, menu: Menu?, isChecked: (MenuItem) -> Boolean): Boolean { + if (menu == null) return false + var hasCheckedItem = false menu.forEach { + val checked = isChecked(it) || checkMenu(context, it.subMenu, isChecked) + hasCheckedItem = hasCheckedItem || checked it.title = SpannableString(it.title.toString()).also { span -> - if (isChecked(it)) span.setSpan( + if (checked) span.setSpan( ForegroundColorSpan(resolveColorAttr(context, R.attr.colorAccent)), 0, span.length, Spannable.SPAN_INCLUSIVE_EXCLUSIVE ) } } + return hasCheckedItem } } \ No newline at end of file diff --git a/app/src/main/res/layout/item_calendar.xml b/app/src/main/res/layout/item_calendar.xml index 47d3121..4068da4 100644 --- a/app/src/main/res/layout/item_calendar.xml +++ b/app/src/main/res/layout/item_calendar.xml @@ -36,6 +36,8 @@ app:layout_constraintTop_toTopOf="parent"/>