diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/SettingDatePickerBackgroundFromHandler.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/SettingDatePickerBackgroundFromHandler.png
new file mode 100644
index 000000000000..6f3b2874ca73
Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/SettingDatePickerBackgroundFromHandler.png differ
diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/SettingEditorBackgroundFromHandler.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/SettingEditorBackgroundFromHandler.png
new file mode 100644
index 000000000000..b084c5796654
Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/SettingEditorBackgroundFromHandler.png differ
diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/SettingEntryBackgroundFromHandler.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/SettingEntryBackgroundFromHandler.png
new file mode 100644
index 000000000000..06c84d89236e
Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/SettingEntryBackgroundFromHandler.png differ
diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/SettingTimePickerBackgroundFromHandler.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/SettingTimePickerBackgroundFromHandler.png
new file mode 100644
index 000000000000..db864e38d3f6
Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/SettingTimePickerBackgroundFromHandler.png differ
diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue18720.xaml b/src/Controls/tests/TestCases.HostApp/Issues/Issue18720.xaml
new file mode 100644
index 000000000000..308c7f3dcc42
--- /dev/null
+++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue18720.xaml
@@ -0,0 +1,61 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue18720.xaml.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue18720.xaml.cs
new file mode 100644
index 000000000000..c679d52791ce
--- /dev/null
+++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue18720.xaml.cs
@@ -0,0 +1,117 @@
+using System;
+using Microsoft.Maui;
+using Microsoft.Maui.Controls;
+using Microsoft.Maui.Controls.Xaml;
+using Microsoft.Maui.Graphics;
+using Microsoft.Maui.Hosting;
+
+namespace Maui.Controls.Sample.Issues
+{
+ [XamlCompilation(XamlCompilationOptions.Compile)]
+ [Issue(IssueTracker.Github, 18720, "Setting the background property of AppCompatEditText (Entry) in a handler mapping does not work", PlatformAffected.Android)]
+ public partial class Issue18720 : ContentPage
+ {
+ public Issue18720()
+ {
+ InitializeComponent();
+ UpdateEntryBackgroundColor();
+ UpdateEntryBackground();
+ }
+
+ void OnUpdateBackgroundColorButtonClicked(object sender, System.EventArgs e)
+ {
+ UpdateEntryBackgroundColor();
+ }
+
+ void OnClearBackgroundColorButtonClicked(object sender, System.EventArgs e)
+ {
+ BackgroundColorEntry.BackgroundColor = null;
+ }
+
+ void OnUpdateBackgroundButtonClicked(object sender, System.EventArgs e)
+ {
+ UpdateEntryBackground();
+ }
+
+ void OnClearBackgroundButtonClicked(object sender, System.EventArgs e)
+ {
+ BackgroundEntry.Background = null;
+ }
+
+ void OnTestButtonClicked(object sender, EventArgs e)
+ {
+ TestLayout.IsVisible = false;
+ }
+
+ void UpdateEntryBackgroundColor()
+ {
+ Random rnd = new Random();
+ Color backgroundColor = Color.FromRgba(rnd.Next(256), rnd.Next(256), rnd.Next(256), 255);
+ BackgroundColorEntry.BackgroundColor = backgroundColor;
+ }
+
+ void UpdateEntryBackground()
+ {
+ Random rnd = new Random();
+ Color startColor = Color.FromRgba(rnd.Next(256), rnd.Next(256), rnd.Next(256), 255);
+ Color endColor = Color.FromRgba(rnd.Next(256), rnd.Next(256), rnd.Next(256), 255);
+
+ BackgroundEntry.Background = new LinearGradientBrush
+ {
+ EndPoint = new Point(1, 0),
+ GradientStops = new GradientStopCollection
+ {
+ new GradientStop { Color = startColor },
+ new GradientStop { Color = endColor, Offset = 1 }
+ }
+ };
+ }
+ }
+
+ public class Issue18720Entry1 : Entry
+ {
+
+ }
+
+ public class Issue18720Entry2 : Entry
+ {
+
+ }
+
+ public static class Issue18720Extensions
+ {
+ public static MauiAppBuilder Issue18720AddMappers(this MauiAppBuilder builder)
+ {
+ builder.ConfigureMauiHandlers(handlers =>
+ {
+ Microsoft.Maui.Handlers.EntryHandler.Mapper.AppendToMapping(nameof(Issue18720Entry1), (handler, view) =>
+ {
+ if (view is Issue18720Entry1)
+ {
+#if ANDROID
+ handler.PlatformView.Background = null;
+ handler.PlatformView.SetBackgroundColor(Android.Graphics.Color.Pink);
+ handler.PlatformView.SetTextColor(Android.Graphics.Color.WhiteSmoke);
+#endif
+ }
+ });
+
+ Microsoft.Maui.Handlers.EntryHandler.Mapper.AppendToMapping(nameof(Issue18720Entry2), (handler, view) =>
+ {
+ if (view is Issue18720Entry2)
+ {
+#if ANDROID
+ Android.Graphics.Drawables.GradientDrawable gd = new Android.Graphics.Drawables.GradientDrawable();
+ gd.SetCornerRadius(10);
+ gd.SetStroke(2, Android.Graphics.Color.Violet);
+ handler.PlatformView.Background = gd;
+ handler.PlatformView.SetTextColor(Android.Graphics.Color.DeepPink);
+#endif
+ }
+ });
+ });
+
+ return builder;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue18720DatePicker.xaml b/src/Controls/tests/TestCases.HostApp/Issues/Issue18720DatePicker.xaml
new file mode 100644
index 000000000000..b2d4ec6ebdf9
--- /dev/null
+++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue18720DatePicker.xaml
@@ -0,0 +1,61 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue18720DatePicker.xaml.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue18720DatePicker.xaml.cs
new file mode 100644
index 000000000000..684549d53ec7
--- /dev/null
+++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue18720DatePicker.xaml.cs
@@ -0,0 +1,117 @@
+using System;
+using Microsoft.Maui;
+using Microsoft.Maui.Controls;
+using Microsoft.Maui.Controls.Xaml;
+using Microsoft.Maui.Graphics;
+using Microsoft.Maui.Hosting;
+
+namespace Maui.Controls.Sample.Issues
+{
+ [XamlCompilation(XamlCompilationOptions.Compile)]
+ [Issue(IssueTracker.ManualTest, "18720 DatePicker", "Setting the background property of AppCompatEditText (DatePicker) in a handler mapping does not work", PlatformAffected.Android)]
+ public partial class Issue18720DatePicker : ContentPage
+ {
+ public Issue18720DatePicker()
+ {
+ InitializeComponent();
+ UpdateDatePickerBackgroundColor();
+ UpdateDatePickerBackground();
+ }
+
+ void OnUpdateBackgroundColorButtonClicked(object sender, EventArgs e)
+ {
+ UpdateDatePickerBackgroundColor();
+ }
+
+ void OnClearBackgroundColorButtonClicked(object sender, EventArgs e)
+ {
+ BackgroundColorDatePicker.BackgroundColor = null;
+ }
+
+ void OnUpdateBackgroundButtonClicked(object sender, EventArgs e)
+ {
+ UpdateDatePickerBackground();
+ }
+
+ void OnClearBackgroundButtonClicked(object sender, EventArgs e)
+ {
+ BackgroundDatePicker.Background = null;
+ }
+
+ void OnTestButtonClicked(object sender, EventArgs e)
+ {
+ TestLayout.IsVisible = false;
+ }
+
+ void UpdateDatePickerBackgroundColor()
+ {
+ Random rnd = new Random();
+ Color backgroundColor = Color.FromRgba(rnd.Next(256), rnd.Next(256), rnd.Next(256), 255);
+ BackgroundColorDatePicker.BackgroundColor = backgroundColor;
+ }
+
+ void UpdateDatePickerBackground()
+ {
+ Random rnd = new Random();
+ Color startColor = Color.FromRgba(rnd.Next(256), rnd.Next(256), rnd.Next(256), 255);
+ Color endColor = Color.FromRgba(rnd.Next(256), rnd.Next(256), rnd.Next(256), 255);
+
+ BackgroundDatePicker.Background = new LinearGradientBrush
+ {
+ EndPoint = new Point(1, 0),
+ GradientStops = new GradientStopCollection
+ {
+ new GradientStop { Color = startColor },
+ new GradientStop { Color = endColor, Offset = 1 }
+ }
+ };
+ }
+ }
+
+ public class Issue18720DatePicker1 : DatePicker
+ {
+
+ }
+
+ public class Issue18720DatePicker2 : DatePicker
+ {
+
+ }
+
+ public static class Issue18720DatePickerExtensions
+ {
+ public static MauiAppBuilder Issue18720DatePickerAddMappers(this MauiAppBuilder builder)
+ {
+ builder.ConfigureMauiHandlers(handlers =>
+ {
+ Microsoft.Maui.Handlers.DatePickerHandler.Mapper.AppendToMapping(nameof(Issue18720DatePicker1), (handler, view) =>
+ {
+ if (view is Issue18720DatePicker1)
+ {
+#if ANDROID
+ handler.PlatformView.Background = null;
+ handler.PlatformView.SetBackgroundColor(Android.Graphics.Color.Pink);
+ handler.PlatformView.SetTextColor(Android.Graphics.Color.WhiteSmoke);
+#endif
+ }
+ });
+
+ Microsoft.Maui.Handlers.DatePickerHandler.Mapper.AppendToMapping(nameof(Issue18720DatePicker2), (handler, view) =>
+ {
+ if (view is Issue18720DatePicker2)
+ {
+#if ANDROID
+ Android.Graphics.Drawables.GradientDrawable gd = new Android.Graphics.Drawables.GradientDrawable();
+ gd.SetCornerRadius(10);
+ gd.SetStroke(2, Android.Graphics.Color.Violet);
+ handler.PlatformView.Background = gd;
+ handler.PlatformView.SetTextColor(Android.Graphics.Color.DeepPink);
+#endif
+ }
+ });
+ });
+
+ return builder;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue18720Editor.xaml b/src/Controls/tests/TestCases.HostApp/Issues/Issue18720Editor.xaml
new file mode 100644
index 000000000000..539461dcda26
--- /dev/null
+++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue18720Editor.xaml
@@ -0,0 +1,61 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue18720Editor.xaml.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue18720Editor.xaml.cs
new file mode 100644
index 000000000000..f62a78e61c8f
--- /dev/null
+++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue18720Editor.xaml.cs
@@ -0,0 +1,117 @@
+using System;
+using Microsoft.Maui;
+using Microsoft.Maui.Controls;
+using Microsoft.Maui.Controls.Xaml;
+using Microsoft.Maui.Graphics;
+using Microsoft.Maui.Hosting;
+
+namespace Maui.Controls.Sample.Issues
+{
+ [XamlCompilation(XamlCompilationOptions.Compile)]
+ [Issue(IssueTracker.Github, "18720 Editor", "Setting the background property of AppCompatEditText (Editor) in a handler mapping does not work", PlatformAffected.Android)]
+ public partial class Issue18720Editor : ContentPage
+ {
+ public Issue18720Editor()
+ {
+ InitializeComponent();
+ UpdateEditorBackgroundColor();
+ UpdateEditorBackground();
+ }
+
+ void OnUpdateBackgroundColorButtonClicked(object sender, System.EventArgs e)
+ {
+ UpdateEditorBackgroundColor();
+ }
+
+ void OnClearBackgroundColorButtonClicked(object sender, System.EventArgs e)
+ {
+ BackgroundColorEditor.BackgroundColor = null;
+ }
+
+ void OnUpdateBackgroundButtonClicked(object sender, System.EventArgs e)
+ {
+ UpdateEditorBackground();
+ }
+
+ void OnClearBackgroundButtonClicked(object sender, System.EventArgs e)
+ {
+ BackgroundEditor.Background = null;
+ }
+
+ void OnTestButtonClicked(object sender, EventArgs e)
+ {
+ TestLayout.IsVisible = false;
+ }
+
+ void UpdateEditorBackgroundColor()
+ {
+ Random rnd = new Random();
+ Color backgroundColor = Color.FromRgba(rnd.Next(256), rnd.Next(256), rnd.Next(256), 255);
+ BackgroundColorEditor.BackgroundColor = backgroundColor;
+ }
+
+ void UpdateEditorBackground()
+ {
+ Random rnd = new Random();
+ Color startColor = Color.FromRgba(rnd.Next(256), rnd.Next(256), rnd.Next(256), 255);
+ Color endColor = Color.FromRgba(rnd.Next(256), rnd.Next(256), rnd.Next(256), 255);
+
+ BackgroundEditor.Background = new LinearGradientBrush
+ {
+ EndPoint = new Point(1, 0),
+ GradientStops = new GradientStopCollection
+ {
+ new GradientStop { Color = startColor },
+ new GradientStop { Color = endColor, Offset = 1 }
+ }
+ };
+ }
+ }
+
+ public class Issue18720Editor1 : Editor
+ {
+
+ }
+
+ public class Issue18720Editor2 : Editor
+ {
+
+ }
+
+ public static class Issue18720EditorExtensions
+ {
+ public static MauiAppBuilder Issue18720EditorAddMappers(this MauiAppBuilder builder)
+ {
+ builder.ConfigureMauiHandlers(handlers =>
+ {
+ Microsoft.Maui.Handlers.EditorHandler.Mapper.AppendToMapping(nameof(Issue18720Editor1), (handler, view) =>
+ {
+ if (view is Issue18720Editor1)
+ {
+#if ANDROID
+ handler.PlatformView.Background = null;
+ handler.PlatformView.SetBackgroundColor(Android.Graphics.Color.Pink);
+ handler.PlatformView.SetTextColor(Android.Graphics.Color.WhiteSmoke);
+#endif
+ }
+ });
+
+ Microsoft.Maui.Handlers.EditorHandler.Mapper.AppendToMapping(nameof(Issue18720Editor2), (handler, view) =>
+ {
+ if (view is Issue18720Editor2)
+ {
+#if ANDROID
+ Android.Graphics.Drawables.GradientDrawable gd = new Android.Graphics.Drawables.GradientDrawable();
+ gd.SetCornerRadius(10);
+ gd.SetStroke(2, Android.Graphics.Color.Violet);
+ handler.PlatformView.Background = gd;
+ handler.PlatformView.SetTextColor(Android.Graphics.Color.DeepPink);
+#endif
+ }
+ });
+ });
+
+ return builder;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue18720TimePicker.xaml b/src/Controls/tests/TestCases.HostApp/Issues/Issue18720TimePicker.xaml
new file mode 100644
index 000000000000..31ca3acce7ef
--- /dev/null
+++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue18720TimePicker.xaml
@@ -0,0 +1,61 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue18720TimePicker.xaml.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue18720TimePicker.xaml.cs
new file mode 100644
index 000000000000..f53e3c7a290e
--- /dev/null
+++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue18720TimePicker.xaml.cs
@@ -0,0 +1,117 @@
+using System;
+using Microsoft.Maui;
+using Microsoft.Maui.Controls;
+using Microsoft.Maui.Controls.Xaml;
+using Microsoft.Maui.Graphics;
+using Microsoft.Maui.Hosting;
+
+namespace Maui.Controls.Sample.Issues
+{
+ [XamlCompilation(XamlCompilationOptions.Compile)]
+ [Issue(IssueTracker.ManualTest, "18720 TimePicker", "Setting the background property of AppCompatEditText (TimePicker) in a handler mapping does not work", PlatformAffected.Android)]
+ public partial class Issue18720TimePicker : ContentPage
+ {
+ public Issue18720TimePicker()
+ {
+ InitializeComponent();
+ UpdateTimePickerBackgroundColor();
+ UpdateTimePickerBackground();
+ }
+
+ void OnUpdateBackgroundColorButtonClicked(object sender, EventArgs e)
+ {
+ UpdateTimePickerBackgroundColor();
+ }
+
+ void OnClearBackgroundColorButtonClicked(object sender, EventArgs e)
+ {
+ BackgroundColorTimePicker.BackgroundColor = null;
+ }
+
+ void OnUpdateBackgroundButtonClicked(object sender, EventArgs e)
+ {
+ UpdateTimePickerBackground();
+ }
+
+ void OnClearBackgroundButtonClicked(object sender, EventArgs e)
+ {
+ BackgroundTimePicker.Background = null;
+ }
+
+ void OnTestButtonClicked(object sender, EventArgs e)
+ {
+ TestLayout.IsVisible = false;
+ }
+
+ void UpdateTimePickerBackgroundColor()
+ {
+ Random rnd = new Random();
+ Color backgroundColor = Color.FromRgba(rnd.Next(256), rnd.Next(256), rnd.Next(256), 255);
+ BackgroundColorTimePicker.BackgroundColor = backgroundColor;
+ }
+
+ void UpdateTimePickerBackground()
+ {
+ Random rnd = new Random();
+ Color startColor = Color.FromRgba(rnd.Next(256), rnd.Next(256), rnd.Next(256), 255);
+ Color endColor = Color.FromRgba(rnd.Next(256), rnd.Next(256), rnd.Next(256), 255);
+
+ BackgroundTimePicker.Background = new LinearGradientBrush
+ {
+ EndPoint = new Point(1, 0),
+ GradientStops = new GradientStopCollection
+ {
+ new GradientStop { Color = startColor },
+ new GradientStop { Color = endColor, Offset = 1 }
+ }
+ };
+ }
+ }
+
+ public class Issue18720TimePicker1 : TimePicker
+ {
+
+ }
+
+ public class Issue18720TimePicker2 : TimePicker
+ {
+
+ }
+
+ public static class Issue18720TimePickerExtensions
+ {
+ public static MauiAppBuilder Issue18720TimePickerAddMappers(this MauiAppBuilder builder)
+ {
+ builder.ConfigureMauiHandlers(handlers =>
+ {
+ Microsoft.Maui.Handlers.TimePickerHandler.Mapper.AppendToMapping(nameof(Issue18720TimePicker1), (handler, view) =>
+ {
+ if (view is Issue18720TimePicker1)
+ {
+#if ANDROID
+ handler.PlatformView.Background = null;
+ handler.PlatformView.SetBackgroundColor(Android.Graphics.Color.Pink);
+ handler.PlatformView.SetTextColor(Android.Graphics.Color.WhiteSmoke);
+#endif
+ }
+ });
+
+ Microsoft.Maui.Handlers.TimePickerHandler.Mapper.AppendToMapping(nameof(Issue18720TimePicker2), (handler, view) =>
+ {
+ if (view is Issue18720TimePicker2)
+ {
+#if ANDROID
+ Android.Graphics.Drawables.GradientDrawable gd = new Android.Graphics.Drawables.GradientDrawable();
+ gd.SetCornerRadius(10);
+ gd.SetStroke(2, Android.Graphics.Color.Violet);
+ handler.PlatformView.Background = gd;
+ handler.PlatformView.SetTextColor(Android.Graphics.Color.DeepPink);
+#endif
+ }
+ });
+ });
+
+ return builder;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Controls/tests/TestCases.HostApp/MauiProgram.cs b/src/Controls/tests/TestCases.HostApp/MauiProgram.cs
index d6422a5af89e..1f2720c45fde 100644
--- a/src/Controls/tests/TestCases.HostApp/MauiProgram.cs
+++ b/src/Controls/tests/TestCases.HostApp/MauiProgram.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using Maui.Controls.Sample.Issues;
using Microsoft.Maui;
using Microsoft.Maui.Controls;
@@ -23,7 +23,11 @@ public static MauiApp CreateMauiApp()
fonts.AddFont("FontAwesome.ttf", "FA");
fonts.AddFont("ionicons.ttf", "Ion");
})
- .Issue21109AddMappers();
+ .Issue21109AddMappers()
+ .Issue18720AddMappers()
+ .Issue18720EditorAddMappers()
+ .Issue18720DatePickerAddMappers()
+ .Issue18720TimePickerAddMappers();
return appBuilder.Build();
}
diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue18720.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue18720.cs
new file mode 100644
index 000000000000..96ab9660ed80
--- /dev/null
+++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue18720.cs
@@ -0,0 +1,30 @@
+#if ANDROID
+using NUnit.Framework;
+using UITest.Appium;
+using UITest.Core;
+
+namespace Microsoft.Maui.TestCases.Tests.Issues
+{
+ public class Issue18720 : _IssuesUITest
+ {
+ public Issue18720(TestDevice device) : base(device)
+ {
+ }
+
+ public override string Issue => "Setting the background property of AppCompatEditText (Entry) in a handler mapping does not work";
+
+ [Test]
+ [Category(UITestCategories.Entry)]
+ public async Task SettingEntryBackgroundFromHandler()
+ {
+ App.WaitForElement("TestButton");
+ App.Tap("TestButton");
+ App.WaitForElement("CustomEntry1");
+
+ await Task.Delay(500);
+
+ VerifyScreenshot();
+ }
+ }
+}
+#endif
\ No newline at end of file
diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue18720DatePicker.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue18720DatePicker.cs
new file mode 100644
index 000000000000..06468cb73d33
--- /dev/null
+++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue18720DatePicker.cs
@@ -0,0 +1,30 @@
+#if ANDROID
+using NUnit.Framework;
+using UITest.Appium;
+using UITest.Core;
+
+namespace Microsoft.Maui.TestCases.Tests.Issues
+{
+ public class Issue18720DatePicker : _IssuesUITest
+ {
+ public Issue18720DatePicker(TestDevice device) : base(device)
+ {
+ }
+
+ public override string Issue => "Setting the background property of AppCompatEditText (DatePicker) in a handler mapping does not work";
+
+ [Test]
+ [Category(UITestCategories.DatePicker)]
+ public async Task SettingDatePickerBackgroundFromHandler()
+ {
+ App.WaitForElement("TestButton");
+ App.Tap("TestButton");
+ App.WaitForElement("CustomDatePicker1");
+
+ await Task.Delay(500);
+
+ VerifyScreenshot();
+ }
+ }
+}
+#endif
\ No newline at end of file
diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue18720Editor.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue18720Editor.cs
new file mode 100644
index 000000000000..91109a9c88df
--- /dev/null
+++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue18720Editor.cs
@@ -0,0 +1,30 @@
+#if ANDROID
+using NUnit.Framework;
+using UITest.Appium;
+using UITest.Core;
+
+namespace Microsoft.Maui.TestCases.Tests.Issues
+{
+ public class Issue18720Editor : _IssuesUITest
+ {
+ public Issue18720Editor(TestDevice device) : base(device)
+ {
+ }
+
+ public override string Issue => "Setting the background property of AppCompatEditText (Editor) in a handler mapping does not work";
+
+ [Test]
+ [Category(UITestCategories.Editor)]
+ public async Task SettingEditorBackgroundFromHandler()
+ {
+ App.WaitForElement("TestButton");
+ App.Tap("TestButton");
+ App.WaitForElement("CustomEditor1");
+
+ await Task.Delay(500);
+
+ VerifyScreenshot();
+ }
+ }
+}
+#endif
\ No newline at end of file
diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue18720TimePicker.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue18720TimePicker.cs
new file mode 100644
index 000000000000..5006a554a763
--- /dev/null
+++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue18720TimePicker.cs
@@ -0,0 +1,30 @@
+#if ANDROID
+using NUnit.Framework;
+using UITest.Appium;
+using UITest.Core;
+
+namespace Microsoft.Maui.TestCases.Tests.Issues
+{
+ public class Issue18720TimePicker : _IssuesUITest
+ {
+ public Issue18720TimePicker(TestDevice device) : base(device)
+ {
+ }
+
+ public override string Issue => "Setting the background property of AppCompatEditText (TimePicker) in a handler mapping does not work";
+
+ [Test]
+ [Category(UITestCategories.TimePicker)]
+ public async Task SettingTimePickerBackgroundFromHandler()
+ {
+ App.WaitForElement("TestButton");
+ App.Tap("TestButton");
+ App.WaitForElement("CustomTimePicker1");
+
+ await Task.Delay(500);
+
+ VerifyScreenshot();
+ }
+ }
+}
+#endif
\ No newline at end of file
diff --git a/src/Core/src/Platform/Android/MauiLayerDrawable.cs b/src/Core/src/Platform/Android/MauiLayerDrawable.cs
new file mode 100644
index 000000000000..5d1b827d49ce
--- /dev/null
+++ b/src/Core/src/Platform/Android/MauiLayerDrawable.cs
@@ -0,0 +1,17 @@
+using Android.Graphics.Drawables;
+using Android.Runtime;
+
+namespace Microsoft.Maui.Platform;
+
+internal class MauiLayerDrawable : LayerDrawable
+{
+ public MauiLayerDrawable(params Drawable[] layers)
+ : base(layers)
+ {
+ }
+
+ protected MauiLayerDrawable(nint javaReference, JniHandleOwnership transfer)
+ : base(javaReference, transfer)
+ {
+ }
+}
diff --git a/src/Core/src/Platform/Android/ViewExtensions.cs b/src/Core/src/Platform/Android/ViewExtensions.cs
index da702477f4d8..df7b0e30096d 100644
--- a/src/Core/src/Platform/Android/ViewExtensions.cs
+++ b/src/Core/src/Platform/Android/ViewExtensions.cs
@@ -9,10 +9,9 @@
using Android.Views.InputMethods;
using Android.Widget;
using AndroidX.AppCompat.Widget;
-using AndroidX.ConstraintLayout.Helper.Widget;
using AndroidX.Core.Content;
using AndroidX.Core.View;
-using AndroidX.Window.Layout;
+using Kotlin;
using Microsoft.Maui.ApplicationModel;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Primitives;
@@ -186,62 +185,83 @@ internal static void UpdateBackground(this TextView platformView, IView view) =>
internal static void UpdateBackground(this EditText platformView, IView view)
{
- if (platformView is null || platformView.Background is null || platformView.Context is null)
+ if (platformView is null || platformView.Context is null)
{
return;
}
- // Remove previous background gradient if any
- if (platformView.Background is MauiDrawable mauiDrawable)
+ // The user has removed the background from the platform view in platform code
+ // so we need to make sure to do absolutely nothing.
+ if (platformView.Background is null)
{
- platformView.Background = null;
- mauiDrawable.Dispose();
+ return;
}
- if (platformView.Background is LayerDrawable layerDrawable)
+ // Get the current background of the edit text so we can make sure to not overwite it
+ // if it is not something that we have set in MAUI.
+ var previousDrawable = platformView.Background;
+
+ // Remove the previous MAUI background (if any).
+ if (previousDrawable is MauiDrawable || previousDrawable is MauiLayerDrawable)
{
platformView.Background = null;
- layerDrawable.Dispose();
+ previousDrawable.Dispose();
+ previousDrawable = null;
}
- // Android will reset the padding when setting a Background drawable
- // So we need to reapply the padding after
- var padLeft = platformView.PaddingLeft;
- var padTop = platformView.PaddingTop;
- var padRight = platformView.PaddingRight;
- var padBottom = platformView.PaddingBottom;
-
+ // Get the new background from the virtual view
var paint = view.Background;
-
- Drawable? defaultBackgroundDrawable = ContextCompat.GetDrawable(platformView.Context, Resource.Drawable.abc_edit_text_material);
-
- var previousDrawable = defaultBackgroundDrawable ?? platformView.Background;
var backgroundDrawable = paint.ToDrawable(platformView.Context);
- if (previousDrawable is null)
- platformView.Background = backgroundDrawable;
- else
+ if (backgroundDrawable is not null || previousDrawable is null)
{
- if (backgroundDrawable is null)
+ // There is a new background to set, or we removed a previous background and
+ // now we have to re-apply just the default "line" background.
+
+ // Regardless of what the new background is, we will need to apply the default
+ // background "line" on top of it.
+ // If for some reason this returns null, then there is nothing we can do because
+ // AndroidX is probably broken since this is a resource from the AndroidX library.
+ var defaultBackground = ContextCompat.GetDrawable(platformView.Context, Resource.Drawable.abc_edit_text_material);
+
+ if (backgroundDrawable is not null)
{
- // The default Drawable of EditText is an InsetDrawable and setting the background we use a LayerDrawable
- // to compose the custom background with the default behavior (bottom line).
- //
- // If the Background is null or is a ColorDrawable, a Custom Handler is being created, removing the default behavior.
- // In this case, we don't want to reset the Drawable to the default one.
- if (platformView.Background is not ColorDrawable)
- platformView.Background = previousDrawable;
+ // The user set some background, so we need to apply it below the default "line".
+ // If there is a broken AndroidX, then nothing we can do but just use ours.
+ SetBackground(platformView, defaultBackground is null
+ ? new MauiLayerDrawable(backgroundDrawable)
+ : new MauiLayerDrawable(backgroundDrawable, defaultBackground));
}
- else
+ else if (previousDrawable is null)
{
-
- LayerDrawable layer = new LayerDrawable(new Drawable[] { backgroundDrawable, previousDrawable });
- platformView.Background = layer;
+ // The user set null in the virtual view (or did not set anything/kept the defaults)
+ // as we just removed a MAUI background from the platform view.
+ // This means we just use the default Material background (the "line").
+ SetBackground(platformView, defaultBackground);
}
}
+ else
+ {
+ // The drawable currently in use was not a MAUI drawable nor are we setting a new
+ // one so just do nothing and keep whatever the user has set in platform code.
+ }
- // Apply previous padding
- platformView.SetPadding(padLeft, padTop, padRight, padBottom);
+ // A helper method to set the background and re-apply the padding since
+ // Android will reset the padding when setting a Background drawable.
+ static void SetBackground(EditText platformView, Drawable? background)
+ {
+ // Cache the current padding
+ var padLeft = platformView.PaddingLeft;
+ var padTop = platformView.PaddingTop;
+ var padRight = platformView.PaddingRight;
+ var padBottom = platformView.PaddingBottom;
+
+ // Set the new background
+ platformView.Background = background;
+
+ // Apply previous padding
+ platformView.SetPadding(padLeft, padTop, padRight, padBottom);
+ }
}
public static void UpdateBackground(this AView platformView, Paint? background) =>