Bug 46512 - FormsAppCompatActivity PushModalAsync
Summary: FormsAppCompatActivity PushModalAsync
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.3.2
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2016-11-04 19:59 UTC by Steven
Modified: 2017-06-15 17:49 UTC (History)
4 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Steven 2016-11-04 19:59:18 UTC
OK, For android:

So using the standard create New CrossPlatform Blank App ( XF Portable)
Then I create a new Page MyPage with BackgroundColor="Transparent".

Then I call MainPage.Navigation.PushModalAsync(new MyPage());

from the portable project. Whilst MyPage appears, it is not transparent.

With MainActivity : FormsAppCompatActivity

But with MainActivity : FormsApplicationActivity

MyPage is transparent. 
So why isn't Page1 transparent?


        public App()
            Button pocButton = new Button
                HorizontalOptions = LayoutOptions.End,
                BackgroundColor = Xamarin.Forms.Color.White,
                Text = "POCBtn",
                TextColor = Xamarin.Forms.Color.Maroon,

            pocButton.Clicked += OnButtonClicked;
            // The root page of your application
            var content = new ContentPage
                Title = "Demo",
                Content = new StackLayout
                    VerticalOptions = LayoutOptions.Center,
                    Children = {
                        new Label {
                            HorizontalTextAlignment = TextAlignment.Center,
                            Text = "Demo"

            MainPage = new NavigationPage(content);

      private void OnButtonClicked(object sender, EventArgs e)
           MainPage.Navigation.PushModalAsync(new Page1());

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
Comment 1 adrianknight89 2016-11-04 21:01:00 UTC
Are you trying to display a popup? Have you tried https://github.com/aritchie/userdialogs?
Comment 2 Steven 2016-11-04 21:41:56 UTC
Thankyou for the reply,
no I haven't tried that, I will see if it works and get back.
Comment 3 Steven 2016-11-05 10:39:44 UTC
Sadly the aritchie UserDialogs aren't suitable, but thankyou for the link.

So on the transparency , have also tried varying the opacity, whilst the color of the background is dimmed,, it is not translucent like it used to be with FormsApplicationActivity.

Is this resolvable, or will transparency not be supported on FormsAppCompatActivity?

Comment 4 adrianknight89 2016-11-05 22:53:29 UTC
XF is wrapping pages in some sort of container that has its own background, so that's why transparency does not work at page level. I'm not sure if this was intentional. Unless this is fixed at the wrapper level, there doesn't seem to be a way to use transparent pages.

To answer your question, yes it is resolvable, but I'd like to know why they've made this choice.

Does transparency work for you on other platforms?
Comment 5 Steven 2016-11-06 12:32:40 UTC
Hmmn that's a point, but if it was intentional then it would be reasonable to assume the transparency and opacity properties would be redundant and be removed? I will try and find out the situation on other platforms, as an aside I wonder if FormsApplicationActivity will continue to be supported.
Comment 6 adrianknight89 2016-11-07 02:08:26 UTC
AppCompat should be the future, and I agree that if opacity is not supported, then it shouldn't be a Page property. As for transparent background, I think they could throw an exception on Transparent since BackgroundColor is still valid for other colors.
Comment 7 adrianknight89 2016-11-07 02:22:33 UTC
Both of these, however, can be breaking changes. Perhaps, the best is to log a warning message to the standard output stream.
Comment 8 Steven 2016-11-11 15:09:17 UTC
As don't do iOS, I have asked on the forums for confirmation on this platform and maybe UWP as a bonus, this may occur or not.
At which point Xamarin Forms Themes may be broken for iOS and UWP, but is for Android.
Excuse the question, but what happens next?
Looking at the bug list(s), There seem to be a lot of bugs unassigned, I am guessing that Xamarin look at the bug list, employ some sort of rating system and choose some to deal with first, and something that breaks Xamarin Forms Themes sounds quite important.
How do I log a warning msg on the standard output stream?
Many Thanks
Comment 9 adrianknight89 2016-11-13 02:28:38 UTC
I haven't looked at Themes, and I'm not sure how reliable they are. When I said to log a message, I meant it should/could be done on the XF side in Page.cs. However, I noticed that Trace.WriteLine is not a PCL method, so it could only be a debug option.

Instead of pushing a transparent modal, can you make your popup part of your original page? You could display it on some kind of user action such as a button click.

     <Grid BackgroundColor="Transparent" IsVisible="False" IsEnabled="False">   </Grid>

So, the second grid is laid on top of the first and should be made visible when you need to show a popup.
Comment 10 Steven 2016-11-17 13:46:36 UTC
Thanks for the reply.

Sadly the Grid solution wont work, as the popup page needs to be separate from the page beneath it, so that other pages can be moved around the navigation stack.
Also on pushmodalasync() the new page seems to be sliding in from the bottom
and taking a discernible amount of time to do it.

This Bug 46512 doesn't seem to have a status as a bug, or not recognised as a bug. Do you happen to know how I can clarify what its status is? 

Many Thanks
Comment 11 Steven 2016-11-22 20:03:04 UTC
Hi looking in the Xamarin Source code, a solution that seems to work is adding the line

 "_backgroundView.Alpha = (float)modal.Opacity;"

In the ModalContainer constructor:

namespace Xamarin.Forms.Platform.Android.AppCompat

public ModalContainer(Context context, Page modal) : base(context)
		_modal = modal;

                _backgroundView = new global::Android.Views.View(context);

                _backgroundView.Alpha = (float)modal.Opacity; //sst


		Android.Platform.SetPageContext(modal, context);
		_renderer = Android.Platform.CreateRenderer(modal);
		Android.Platform.SetRenderer(modal, _renderer);


I am unfamiliar with the internals of the platform, but this is my guess at it: 

The color returned below has a fixed default value of 255,238,238,238, ie Alpha = 255.

var color = new AColor(ContextCompat.GetColor(context, background.ResourceId));

Then any custom backgroundcolor is being set such that it applies to the renderer in

_renderer = Android.Platform.CreateRenderer(modal);

But even though the developer can set an alpha value of 0 here, it the page is showing as faded and not transparent, whereas setting 
_backgroundView.Alpha = (float)modal.Opacity; 
as above makes the Page transparent.

So assuming a Page can contain multiple views of which _backgroundView and the renderer are 2.
If a developer sets a custom backgroundcolor, it is setting the background color of the renderer, and as the renderer is added to the viewgroup after the _backgroundview, setting the renderer transparent only shows the view beneath it and not the Page beneath it as intended?
To achieve Page Opacity, would either the backgroundview have to be transparent or equivalently have the same opacity of all view above it ( in this case the renderer )?

So would including
_backgroundView.Alpha = (float)modal.Opacity;
be an acceptable solution that could be included in the next release?

Many thanks.
Comment 12 adrianknight89 2016-11-23 15:14:07 UTC
The only way a bug can be confirmed is when XF team decides it's a bug. It could also be marked as an enhancement. Unfortunately, there are many many bugs still with the "NEW" status. 

I've seen the Android code before. I think another solution is to remove _backgroundView. I don't believe adding an opacity parameter to the construction will be seen as a good design, so probably the solution is to remove _backgroundView when some flag is set.

This is only Android. The same solution should apply across all platforms. If you like, you could dig around and see what you find and maybe submit a PR to see what the team thinks.
Comment 13 Steven 2016-11-24 08:32:33 UTC
OK will have a dig around.
Comment 15 Paul DiPietro [MSFT] 2017-06-15 17:49:33 UTC
We have a Popover control on our roadmap for the future which may be in line with what you're looking for.