From 780e3362a5f3084d7d250fb2e985f8a71f39dbb9 Mon Sep 17 00:00:00 2001 From: mcarare Date: Wed, 27 Jan 2021 11:59:04 +0200 Subject: [PATCH] For #17464: Handle selected item background programmatically. --- .../quicksettings/WebsitePermissionsView.kt | 28 +++++++++++++++++-- .../drawable/etp_spinner_item_background.xml | 2 +- app/src/main/res/values/colors.xml | 3 ++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/settings/quicksettings/WebsitePermissionsView.kt b/app/src/main/java/org/mozilla/fenix/settings/quicksettings/WebsitePermissionsView.kt index 8cc26d7fb7fa..dc1735d33712 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/quicksettings/WebsitePermissionsView.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/quicksettings/WebsitePermissionsView.kt @@ -12,6 +12,7 @@ import android.widget.ArrayAdapter import android.widget.TextView import androidx.annotation.VisibleForTesting import androidx.appcompat.widget.AppCompatSpinner +import androidx.core.content.ContextCompat import androidx.core.view.isVisible import kotlinx.android.extensions.LayoutContainer import kotlinx.android.synthetic.main.quicksettings_permissions.view.* @@ -151,11 +152,34 @@ class WebsitePermissionsView( } val selectedIndex = permissionState.options.indexOf(permissionState.autoplayValue) - val adapter = ArrayAdapter( + + val adapter = object : ArrayAdapter( context, R.layout.quicksettings_permission_spinner_item, permissionState.options - ) + ) { + override fun getDropDownView( + position: Int, + convertView: View?, + parent: ViewGroup + ): View { + val view = super.getDropDownView( + position, + convertView, + parent + ) + if (position == viewHolder.status.selectedItemPosition) { + view.setBackgroundColor( + ContextCompat.getColor( + context, + R.color.spinner_selected_item + ) + ) + } + return view + } + } + adapter.setDropDownViewResource(R.layout.quicksetting_permission_spinner_dropdown) viewHolder.status.adapter = adapter diff --git a/app/src/main/res/drawable/etp_spinner_item_background.xml b/app/src/main/res/drawable/etp_spinner_item_background.xml index 642b276e341d..05f0f2eea0a6 100644 --- a/app/src/main/res/drawable/etp_spinner_item_background.xml +++ b/app/src/main/res/drawable/etp_spinner_item_background.xml @@ -5,7 +5,7 @@ - + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 169b324551fa..5f2d1b1a9101 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -419,4 +419,7 @@ @color/primary_text_light_theme @color/primary_text_light_theme + + + #1415141A