-
Notifications
You must be signed in to change notification settings - Fork 2k
[Android] ImageButton CornerRadius not being applied - fix #30074
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| namespace Maui.Controls.Sample.Issues; | ||
|
|
||
| [Issue(IssueTracker.Github, 23854, "ImageButton CornerRadius not being applied on Android", PlatformAffected.Android)] | ||
| public class Issue23854 : TestContentPage | ||
| { | ||
| protected override void Init() | ||
| { | ||
| Content = new VerticalStackLayout | ||
| { | ||
| Spacing = 10, | ||
| Children = | ||
| { | ||
| new ImageButton | ||
| { | ||
| AutomationId = "ImageButton", | ||
| HeightRequest = 50, | ||
| WidthRequest = 50, | ||
| CornerRadius = 25, | ||
| Source = "vegetables.png", | ||
| Aspect = Aspect.AspectFill | ||
| }, | ||
| new ImageButton | ||
| { | ||
| HeightRequest = 50, | ||
| WidthRequest = 100, | ||
| CornerRadius = 25, | ||
| Source = "vegetables.png", | ||
| Aspect = Aspect.AspectFill | ||
| }, | ||
| new ImageButton | ||
| { | ||
| HeightRequest = 100, | ||
| WidthRequest = 50, | ||
| CornerRadius = 25, | ||
| Source = "vegetables.png", | ||
| Aspect = Aspect.AspectFill | ||
| }, | ||
| new ImageButton | ||
| { | ||
| HeightRequest = 20, | ||
| WidthRequest = 100, | ||
| CornerRadius = 20, | ||
| Source = "vegetables.png", | ||
| Aspect = Aspect.AspectFill | ||
| } | ||
| } | ||
| }; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
|
|
||
| public class Issue23854 : _IssuesUITest | ||
| { | ||
| public Issue23854(TestDevice testDevice) : base(testDevice) { } | ||
|
|
||
| public override string Issue => "ImageButton CornerRadius not being applied on Android"; | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.ImageButton)] | ||
| public void CornerRadiusShouldBeApplied() | ||
| { | ||
| App.WaitForElement("ImageButton"); | ||
| VerifyScreenshot(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,8 @@ | |||||||||||
| using Android.Content; | ||||||||||||
| using Android.Content.Res; | ||||||||||||
| using Android.Graphics.Drawables; | ||||||||||||
| using Google.Android.Material.ImageView; | ||||||||||||
| using Google.Android.Material.Shape; | ||||||||||||
| using Microsoft.Maui.Graphics; | ||||||||||||
| using AColor = Android.Graphics.Color; | ||||||||||||
| using AView = Android.Views.View; | ||||||||||||
|
|
@@ -50,6 +52,20 @@ internal static bool UpdateMauiRippleDrawableStroke(this AView platformView, IBu | |||||||||||
| gradientDrawable.SetCornerRadius(radius); | ||||||||||||
| maskDrawable.SetCornerRadius(radius); | ||||||||||||
|
|
||||||||||||
| if (platformView is ShapeableImageView shapeableImageView) | ||||||||||||
| { | ||||||||||||
| // Update the ShapeAppearanceModel to match the stroke radius | ||||||||||||
| // so that the corners are rounded correctly. | ||||||||||||
| shapeableImageView.ShapeAppearanceModel = | ||||||||||||
| shapeableImageView.ShapeAppearanceModel | ||||||||||||
| .ToBuilder() | ||||||||||||
| .SetTopLeftCorner(CornerFamily.Rounded, radius) | ||||||||||||
| .SetTopRightCorner(CornerFamily.Rounded, radius) | ||||||||||||
| .SetBottomLeftCorner(CornerFamily.Rounded, radius) | ||||||||||||
| .SetBottomRightCorner(CornerFamily.Rounded, radius) | ||||||||||||
|
Comment on lines
+62
to
+65
|
||||||||||||
| .SetTopLeftCorner(CornerFamily.Rounded, radius) | |
| .SetTopRightCorner(CornerFamily.Rounded, radius) | |
| .SetBottomLeftCorner(CornerFamily.Rounded, radius) | |
| .SetBottomRightCorner(CornerFamily.Rounded, radius) | |
| .SetAllCorners(CornerFamily.Rounded, radius) |

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you include a couple of samples using the
BorderWidthandBorderColorproperties?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rounding doesn't quite work with non-transparent images with borderWidth and borderColor. @mattleibow was writing about it here #21259 (comment)