Похоже, что Maui использует Androidx.appcompat.app.alertdialog и внутренние текстовые изменения elements в listView строится. Насколько я настраивался:
Не знает, почему цвет текстового Theme.appcompat.light.dialog.alert Чтобы иметь его в черном). Содержание styles.xaml не имеет реального эффекта. Итак, как мне изменить цвет текста?
Код: Выделить всё
Title="Select a monkey"
TitleColor="Blue"
TextColor="Yellow">
Baboon
Capuchin Monkey
Blue Monkey
Squirrel Monkey
Golden Lion Tamarin
Howler Monkey
Japanese Macaque
Код: Выделить всё
@style/CustomPickerDialog
@android:color/black
#0000FF
#FF0000
Код: Выделить всё
[Activity(Theme = "@style/AppTheme.Base", ...]
< /code>
Одна альтернатива, как уже упоминалось, будет реализовать вас собственный сборщик для Android. Напримерpublic class CustomPicker : Picker
{
public static readonly BindableProperty ItemColorProperty =
BindableProperty.Create(nameof(ItemColor), typeof(Color), typeof(CustomPicker), Colors.Black);
public Color ItemColor
{
get => (Color)GetValue(ItemColorProperty);
set => SetValue(ItemColorProperty, value);
}
}
Код: Выделить всё
public class CustomPickerHandler : PickerHandler
{
public static IPropertyMapper PropertyMapper = new PropertyMapper(PickerHandler.Mapper)
{
[nameof(CustomPicker.ItemColor)] = MapItemColor
};
public CustomPickerHandler() : base(PropertyMapper)
{
}
private static void MapItemColor(IElementHandler handler, IElement view)
{
#if ANDROID
if (handler is CustomPickerHandler pickerHandler && view is CustomPicker picker && pickerHandler.PlatformView != null)
{
var context = pickerHandler.PlatformView.Context;
if (context != null && picker.ItemColor != null)
{
var adapter = new CustomArrayAdapter(context, Android.Resource.Layout.SimpleListItemSingleChoice, picker.Items.ToArray(), picker.ItemColor.ToPlatform());
pickerHandler.PlatformView.SetOnClickListener(new ClickListener(() =>
{
int selectedIndex = picker.SelectedIndex;
var dialog = new AppCompatAlertDialog.Builder(context)
.SetTitle(picker.Title)
.SetSingleChoiceItems(adapter, selectedIndex, (s, e) => selectedIndex = e.Which)
.SetPositiveButton("OK", (s, e) => picker.SelectedIndex = selectedIndex)
.SetNegativeButton("Cancel", (s, e) => { })
.Create();
dialog?.Show();
}));
}
}
#endif
}
}
class CustomArrayAdapter : ArrayAdapter
{
private readonly Android.Graphics.Color _textColor;
public CustomArrayAdapter(Context context, int resource, string[] items, Android.Graphics.Color textColor)
: base(context, resource, items)
{
_textColor = textColor;
}
public override Android.Views.View GetView(int position, Android.Views.View convertView, Android.Views.ViewGroup parent)
{
var view = base.GetView(position, convertView, parent);
if (view is TextView textView)
{
textView.SetTextColor(_textColor);
}
return view;
}
}
class ClickListener : Java.Lang.Object, Android.Views.View.IOnClickListener
{
private readonly Action _action;
public ClickListener(Action action) => _action = action;
public void OnClick(Android.Views.View v) => _action?.Invoke();
}
Код: Выделить всё
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp()
...
.ConfigureMauiHandlers(handlers =>
{
handlers.AddHandler();
});
Код: Выделить всё
Baboon
Capuchin Monkey
Blue Monkey
Squirrel Monkey
Golden Lion Tamarin
Howler Monkey
Japanese Macaque
, но вы должны реализовать, что вы выбираете, что вы выбираете, что вы выбираете, что вы выбираете, вы выбираете. Кнопка, если вы выберете элемент и т. Д. Есть ли подходящий отладчик макета? Живое визуальное дерево не отображает диалог предупреждения ...
Подробнее здесь: https://stackoverflow.com/questions/796 ... on-android
Мобильная версия