diff --git a/android-components/components/browser/menu2/src/main/java/mozilla/components/browser/menu2/BrowserMenuController.kt b/android-components/components/browser/menu2/src/main/java/mozilla/components/browser/menu2/BrowserMenuController.kt index bed19396a161..be249708ef4f 100644 --- a/android-components/components/browser/menu2/src/main/java/mozilla/components/browser/menu2/BrowserMenuController.kt +++ b/android-components/components/browser/menu2/src/main/java/mozilla/components/browser/menu2/BrowserMenuController.kt @@ -11,6 +11,7 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout import mozilla.components.browser.menu2.ext.displayPopup import mozilla.components.browser.menu2.view.MenuView import mozilla.components.concept.menu.MenuController +import mozilla.components.concept.menu.MenuStyle import mozilla.components.concept.menu.Orientation import mozilla.components.concept.menu.Side import mozilla.components.concept.menu.candidate.MenuCandidate @@ -22,9 +23,11 @@ import mozilla.components.support.base.observer.ObserverRegistry /** * Controls a popup menu composed of MenuCandidate objects. * @param visibleSide Sets the menu to open with either the start or end visible. + * @param style Custom styling for this menu controller. */ class BrowserMenuController( - private val visibleSide: Side = Side.START + private val visibleSide: Side = Side.START, + private val style: MenuStyle? = null ) : MenuController, Observable by ObserverRegistry() { private var currentPopupInfo: PopupMenuInfo? = null @@ -48,6 +51,7 @@ class BrowserMenuController( // Show nested list if present, or the standard menu candidates list. submitList(menuCandidates) setVisibleSide(visibleSide) + style?.let { setStyle(it) } } return MenuPopupWindow(view).apply { diff --git a/android-components/components/browser/menu2/src/main/java/mozilla/components/browser/menu2/view/MenuView.kt b/android-components/components/browser/menu2/src/main/java/mozilla/components/browser/menu2/view/MenuView.kt index 769cb251f43b..1666d2a687ca 100644 --- a/android-components/components/browser/menu2/src/main/java/mozilla/components/browser/menu2/view/MenuView.kt +++ b/android-components/components/browser/menu2/src/main/java/mozilla/components/browser/menu2/view/MenuView.kt @@ -12,10 +12,12 @@ import android.view.LayoutInflater import android.view.View import android.widget.FrameLayout import androidx.annotation.VisibleForTesting +import androidx.cardview.widget.CardView import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import mozilla.components.browser.menu2.R import mozilla.components.browser.menu2.adapter.MenuCandidateListAdapter +import mozilla.components.concept.menu.MenuStyle import mozilla.components.concept.menu.Side import mozilla.components.concept.menu.candidate.MenuCandidate import mozilla.components.concept.menu.candidate.NestedMenuCandidate @@ -36,6 +38,7 @@ class MenuView @JvmOverloads constructor( dismiss = { onDismiss() }, reopenMenu = { onReopenMenu(it) } ) + private val cardView: CardView private val recyclerView: RecyclerView /** @@ -51,6 +54,7 @@ class MenuView @JvmOverloads constructor( init { View.inflate(context, R.layout.mozac_browser_menu2_view, this) + cardView = findViewById(R.id.mozac_browser_menu_cardView) recyclerView = findViewById(R.id.mozac_browser_menu_recyclerView) recyclerView.layoutManager = layoutManager recyclerView.adapter = menuAdapter @@ -75,6 +79,10 @@ class MenuView @JvmOverloads constructor( } } + fun setStyle(style: MenuStyle) { + style.backgroundColor?.let { cardView.setCardBackgroundColor(it) } + } + @VisibleForTesting internal fun scrollOnceToTheBottom(recyclerView: RecyclerView) { recyclerView.onNextGlobalLayout { diff --git a/android-components/components/browser/menu2/src/main/res/layout/mozac_browser_menu2_view.xml b/android-components/components/browser/menu2/src/main/res/layout/mozac_browser_menu2_view.xml index f1b50bf36a84..1e05515a6f51 100644 --- a/android-components/components/browser/menu2/src/main/res/layout/mozac_browser_menu2_view.xml +++ b/android-components/components/browser/menu2/src/main/res/layout/mozac_browser_menu2_view.xml @@ -11,6 +11,7 @@