Я сделал собственный popupBackground с угловым радиусом 16dp. Проблема в том, что элементы внутри этого всплывающего окна могут иметь цвет фона, который не повторяется после его родительского всплывающего окна, и я не понимаю, как это сделать, поскольку я не вижу никакого свойства типа ClipToBounds. То же самое происходит с эффектом пульсации при нажатии на элемент. Изображение, представляющее то, что у меня есть прямо сейчас, и код, используемый для его создания:
Определение спиннера:
<androidx.appcompat.widget.AppCompatSpinner
android:id="@+id/ItemOptionsSpinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:dropDownWidth="wrap_content"
android:popupBackground="@drawable/spinner_background"
android:paddingRight="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintHorizontal_bias="1"
android:spinnerMode="dropdown"
android:visibility="invisible" />
spinner_background.xml внутри папки с возможностью рисования:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="16dp" />
<solid android:color="?android:colorBackground" />
</shape>
SpinnerItemLineDropLayout.xml, представление, используемое для отображения каждого элемента:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/MainLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:paddingHorizontal="@dimen/activityHorizontalPadding"
android:paddingVertical="@dimen/activityVerticalPadding"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/ItemText"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/CheckImage"
style="@style/DefaultTextAppearance.Medium.Big" />
<ImageView
android:id="@+id/CheckImage"
android:paddingLeft="12dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@+id/HelpText"
app:layout_constraintRight_toRightOf="parent"
android:src="@drawable/ic_check_black_18dp"
android:tint="@color/colorPrimaryDark"
tools:ignore="ContentDescription" />
</androidx.constraintlayout.widget.ConstraintLayout>
Код, который я использую внутри адаптера для заполнения элементов, просто для демонстрации того, как я устанавливаю цвет фона самого элемента в зависимости от того, выбран ли элемент счетчиком или нет:
public override View GetDropDownView(Int32 position, View convertView, ViewGroup parent)
{
var view = convertView ?? (parent?.Context == null ? null : LayoutInflater.FromContext(parent.Context)?.Inflate(Resource.Layout.SpinnerItemLineDropLayout, null));
var mainLayout = view.FindViewById<ConstraintLayout>(Resource.Id.MainLayout);
var itemTextView = view.FindViewById<TextView>(Resource.Id.ItemText);
var checkImageView = view.FindViewById<ImageView>(Resource.Id.CheckImage);
itemTextView.Text = this._items[position].Text.GetText();
checkImageView.SetImageResource(this.SelectedPosition == position ? Resource.Drawable.ic_check_black_18dp : 0);
if (this.SelectedPosition == position)
mainLayout.SetBackgroundColor(Color.ParseColor(view.Context.GetString(Resource.Color.colorControlHighlight)));
return view;
}