-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[regression/8.0.0-preview.4.8333] [Android] Setting the background property of AppCompatEditText in a handler mapping does not work #18720
Comments
Came across the same issue just commenting to keep track of this issue. |
also applies to Picker and Editors |
anyone have a workaround? |
@borrmann I expect the team will fix this pretty quickly as it will affect everyone. And probably the controls vendors too. |
Verified this on Visual Studio Enterprise 17.9.0 Preview 1. Repro on Android 14.0-API34(8.0.3), not repro on Android 14.0-API34(7.0.101) with below Project: |
Hello @matt-goldman , it appears this is not a .NET MAUI 8/7 issue. On this post found in StackOverflow, the Android developers shared that to change the edit text line color we must use BackgroundTint, and we should not use BackgroundColor. Honestly, I was like you, I have been using the background color to remove the line color on Android in .NET MAUI 7, but after reviewing I was able to remove the bottom line of the edit text on android in my .NET MAUI 8 projects, by using the following code line on my handler: I updated my article on my blog, reflecting this change: So, based on the findings, I believe this is not a bug of .NET MAUI and instead we were setting wrong the code to hide the Entry form control border in Android. I just wanted to share my grain of salt @jsuarezruiz . I hope this helps other developers! Reference of the official Android documentation: https://developer.android.com/reference/androidx/core/view/TintableBackgroundView Thanks in advance. |
Nice catch @vhugogarcia! Thanks for this, and the write-up too! |
Happy to help. Please feel free to close this issue if you believe it has been solved. |
Do we know what changed between .NET 8 and .NET 7? |
I believe there is still handler.PlatformView.Background setter, that is required to be fixed. Meanwhile we have ability to remove line for entry with Colors.Transparent approach, we still not able to update Background with any native Android.Graphics.Drawables.Drawable in .NET8. |
Hey friends! From reading the comments, it looks like this can be closed. Is there further action required from the MAUI team? Thanks! |
Hi @matt-goldman. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time. |
Hello @samhouts, https://github.com/vitalbit/AndroidEntryBackgroundChangeSample/ master branch - provides .NET 7 project, which works fine. net8-migration branch - provides .NET 8 project, with background issue. The workaround mentioned above provides possibility to remove underline for Android, meanwhile we still can not fully control Background natively for Android, that's why I believe this bug should still be in Open state. |
I have tested it in version 8.06 and still have this issue
|
I came here with the same issue, please this needs attention. |
Any update from the MAUI team on when this will be fixed? This is stopping me from using .NET 8 Android in production. .NET 7 end of life is in May. |
Are there any workarounds, on how to change the line color in EditText and setting a background color in so that it works? If set the BackgroundColor and set the BackgroundTintList in handler, then the whole view gets the color of the tintlist. |
I can confirm this is still happening in 8.0.70 |
Just ran into this too, applying a gradient has no effect in the handler in Android.
MAUI 8.0.70 |
+1 |
This all looks very complicated with the append mapper and/or custom handler. It appears you want to replace the background? We have a feature for that since net6: builder.ConfigureMauiHandlers(handlers =>
{
#if ANDROID
EntryHandler.Mapper.ReplaceMapping<IEntry, IEntryHandler>("Background", (handler, view) =>
{
var platformView = handler.PlatformView;
// 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;
// Set the custom background
var gd = new Android.Graphics.Drawables.GradientDrawable();
gd.SetCornerRadius(3);
gd.SetStroke(1, Android.Graphics.Color.Red);
gd.SetColor(Android.Graphics.Color.Pink);
platformView.Background = gd;
// Apply previous padding
platformView.SetPadding(padLeft, padTop, padRight, padBottom);
});
#endif
}); This results in: |
Thank you! @mattleibow . This is really helpful. |
Thanks but not really what I was trying to achieve, is there a way to apply using this approach to a subclassed control ? this would apply to all entries in the app. I can add a mapper to my custom handler I suppose, it's just pretty clunky... |
@mackayn I was able to apply it for sub-classed control MauiProgram.cs MauiApp.CreateBuilder().ConfigureMauiHandlers(handlers =>
{
handlers.AddHandler(typeof(BorderedEntry), typeof(BorderedEntryHandler));
}); Created BorderedEntryHandler in Platforms/Android, namespace has to be same as of MauiProgram public partial class BorderedEntryHandler : EntryHandler
{
public BorderedEntryHandler()
{
Mapper.ReplaceMapping<IEntry, IEntryHandler>("Background", BorderedEntryMapper);
}
private void BorderedEntryMapper(IEntryHandler handler, IEntry entry)
{
var platformView = handler.PlatformView;
// 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;
// Set the custom background
var gd = new Android.Graphics.Drawables.GradientDrawable();
gd.SetCornerRadius(3);
gd.SetStroke(1, Android.Graphics.Color.Red);
gd.SetColor(Android.Graphics.Color.Pink);
platformView.Background = gd;
// Apply previous padding
platformView.SetPadding(padLeft, padTop, padRight, padBottom);
}
} |
I never thought of consuming the API that way, your 100% right about needing more documentation on mappers, I'm guessing some of these 3.5K open issues are this type of thing, a misunderstanding of the mappers API. That's working very nicely, thanks. |
@mackayn how were you able to make it work for Editor. As soon as I set |
@pmahend1
|
@borrmann Thanks but I had tried the same logic. I am on Android 34 if that matters. |
Sorry, on vacation, not near a dev env but if you setup the correct handler type it works for editor in iOS and Android, don't override ConnectHandler. https://learn.microsoft.com/en-us/dotnet/maui/user-interface/handlers/?view=net-maui-8.0#view-handlers. Use the approach recommended by @mattleibow |
Description
In a .NET MAUI project using the latest .NET 8 RC, setting the background property of a
AppCompatEditText
doesn't seem to work.Using this code:
Has the following results:
❌ Figure: PlatformView background properties not applied, but other mappings are applied
✅ Figure: The same code in .NET 7
Repro is linked below. Repo with working version in .NET 7: https://github.com/matt-goldman/Net7AndroidHandlers
Steps to Reproduce
PlatformView
forEntry
Entry
to your UILink to public reproduction project repository
https://github.com/matt-goldman/Net8AndroidHandlers
Version with bug
8.0.0-preview.4.8333
Is this a regression from previous behavior?
Yes, this used to work in .NET MAUI
Last version that worked well
8.0.0-preview.3.8149
Affected platforms
Android
Affected platform versions
Android - all versions
Did you find any workaround?
I could not find a workaround
Relevant log output
No response
The text was updated successfully, but these errors were encountered: