xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.63k stars 1.87k forks source link

[Bug] Background brush does not support transparency in certain views on Android #12885

Open beeradmoore opened 3 years ago

beeradmoore commented 3 years ago

Description

When attempting to use a SolidColorBrush with a color that contains transparency will result will be inconsistent depending on the view it is applied to and the platform displaying it.

Steps to Reproduce

  1. Create SolidColorBursh with a color with transparency.
  2. Apply it to the Background property of any given view.
  3. See if the underlying view is visible.

Expected Behavior

Matching behavior across views and platforms.

Actual Behavior

Inconsistent behavior across views and platforms.

View type iOS Android
BoxView
Button
ContentView
Grid
StackLayout

Basic Information

Environment

Visual Studio Community 2019 for Mac
Version 8.8 (build 2913)
Installation UUID: c619027d-6cca-48e2-97e5-92785d110708
    GTK+ 2.24.23 (Raleigh theme)
    Xamarin.Mac 6.18.0.23 (d16-6 / 088c73638)

    Package version: 612000093

Mono Framework MDK
Runtime:
    Mono 6.12.0.93 (2020-02/620cf538206) (64-bit)
    Package version: 612000093

Roslyn (Language Service)
3.8.0-5.20515.7+713efb0e68d34ab75faaf709e071e5c2d8d4ed0e

NuGet
Version: 5.8.0.6860

.NET Core SDK
SDK: /usr/local/share/dotnet/sdk/5.0.100/Sdks
SDK Versions:
    5.0.100
    3.1.403
    3.1.402
    3.1.401
    3.1.302
    3.1.301
    3.1.300
    3.1.202
    2.1.810
    2.1.806
MSBuild SDKs: /Applications/Visual Studio.app/Contents/Resources/lib/monodevelop/bin/MSBuild/Current/bin/Sdks

.NET Core Runtime
Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
    5.0.0
    3.1.9
    3.1.8
    3.1.7
    3.1.6
    3.1.5
    3.1.4
    3.0.3
    2.1.23
    2.1.22
    2.1.21
    2.1.20
    2.1.19
    2.1.18

.NET Core 3.1 SDK
SDK: 3.1.403

Xamarin.Profiler
Version: 1.6.13.11
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

Updater
Version: 11

Xamarin.Android
Version: 11.1.0.17 (Visual Studio Community)
Commit: xamarin-android/d16-8/c0e2b8e
Android SDK: /Users/bradmoore/Library/Developer/Xamarin/android-sdk-macosx
    Supported Android versions:
        8.0 (API level 26)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 30.0.4
SDK Build Tools Version: 30.0.2

Build Information: 
Mono: be2226b
Java.Interop: xamarin/java.interop/d16-8@79d9533
ProGuard: Guardsquare/proguard/proguard6.2.2@ebe9000
SQLite: xamarin/sqlite/3.32.1@1a3276b
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-8@2fb1cbc

Microsoft OpenJDK for Mobile
Java SDK: /Users/bradmoore/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.25
1.8.0-25
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Android SDK Manager
Version: 16.8.0.32
Hash: 01a7774
Branch: remotes/origin/d16-8
Build date: 2020-10-13 23:32:30 UTC

Android Device Manager
Version: 16.8.0.45
Hash: fc0af5f
Branch: remotes/origin/d16-8
Build date: 2020-10-13 23:32:54 UTC

Apple Developer Tools
Xcode 12.1 (17222)
Build 12A7403

Xamarin.Mac
Version: 6.22.1.26 (Visual Studio Community)
Hash: 1dc78db1a
Branch: d16-8-xm
Build date: 2020-09-18 17:30:35-0400

Xamarin.iOS
Version: 14.4.1.3 (Visual Studio Community)
Hash: e30c41de3
Branch: d16-8
Build date: 2020-10-20 22:18:50-0400

Xamarin Designer
Version: 16.8.0.495
Hash: 1a7425b8f
Branch: remotes/origin/d16-8
Build date: 2020-10-20 10:51:14 UTC

Build Information
Release ID: 808002913
Git revision: c6189b3851aed1e1aadbef5807d54bd5bb505e5e
Build date: 2020-11-05 07:07:20-05
Build branch: release-8.8
Xamarin extensions: c6189b3851aed1e1aadbef5807d54bd5bb505e5e

Operating System
Mac OS X 10.15.7
Darwin 19.6.0 Darwin Kernel Version 19.6.0
    Thu Oct 29 22:56:45 PDT 2020
    root:xnu-6153.141.2.2~1/RELEASE_X86_64 x86_64

Enabled user installed extensions
MFractor 4.4.0

Build Logs

Screenshots

test_image

Reproduction Link

BackgroundColorTransparencyBug.zip

Workaround

Oddly enough you can workaround this by using a LinearGradientBrush instead.

viewOverlay.Background = new LinearGradientBrush()
{
    GradientStops = new GradientStopCollection()
    {
        new GradientStop(Color.FromRgba(0f, 0f, 1f, 0.5f), 0f),
        new GradientStop(Color.FromRgba(0f, 0f, 1f, 0.5f), 1f),
    },
};
jsuarezruiz commented 3 years ago

Thanks for the detailed feedback, the issue will be fixed with this PR: https://github.com/xamarin/Xamarin.Forms/pull/12888