Skip to content

Commit

Permalink
For mozilla-mobile#17464: Handle selected item background programmati…
Browse files Browse the repository at this point in the history
…cally.
  • Loading branch information
mcarare authored and Amejia481 committed Jan 27, 2021
1 parent 3abda6d commit 780e336
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down Expand Up @@ -151,11 +152,34 @@ class WebsitePermissionsView(
}

val selectedIndex = permissionState.options.indexOf(permissionState.autoplayValue)
val adapter = ArrayAdapter(

val adapter = object : ArrayAdapter<AutoplayValue>(
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

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/etp_spinner_item_background.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true">
<shape>
<solid android:color="#1415141A"/>
<solid android:color="@color/spinner_selected_item"/>
</shape>
</item>
</selector>
3 changes: 3 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -419,4 +419,7 @@
<!-- Tab Counter colors -->
<color name="mozac_ui_tabcounter_default_tint">@color/primary_text_light_theme</color>
<color name="mozac_ui_tabcounter_default_text">@color/primary_text_light_theme</color>

<!-- App Spinners colors -->
<color name="spinner_selected_item">#1415141A</color>
</resources>

0 comments on commit 780e336

Please sign in to comment.