I develop with Xamarin 4.5 and I'm not able to find how to put my application to cover the entire screen (full screen).
For Android and for iOS.
Note: I do not want only an image or a video to cover the entire screen, it should be all the application that should cover the entire screen.
Update 2020-04-29
I found half of the solution, only the Android part (inlcluded in my answer with help of FabriBertani for status bar). I tested it and it works fine. Now I have to find a solution for iPhone (or at least, find a way to test on an iPhone).
On Android add this to the OnCreate method of your MainActivity:
this.Window.AddFlags(WindowManagerFlags.Fullscreen);
For iOS add these values to the info.plist file:
<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
edit: If you want to remove the toolbar too just add this on your xaml pages:
NavigationPage.HasNavigationBar="False"
Or in the C# code behind
public YourPage()
{
InitializeComponent();
NavigationPage.SetHasNavigationBar(this, false);
}
If you want to add this to all your pages, I recommend you to create a base page with this and then use this base page in all your pages.
public class BaseContentPage : ContentPage
{
public BaseContentPage
{
NavigationPage.SetHasNavigationBar(this, false);
}
}
And use it on the xaml:
<?xml version="1.0" encoding="UTF-8"?>
<local:BaseContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:YourNamespace.Pages"
x:Class="YourNamespace.Pages.YourPage">
</local:BaseContentPage>
This is half of the solution. For Android:
In Android Project. Into MainActivity.OnCreate, add:
this.Window.AddFlags(WindowManagerFlags.Fullscreen); // Hide StatusBar, from FabriBertani
MessagingCenter.Subscribe<Object>(this, "HideOsNavigationBar", (sender) =>
{
int uiOptions = (int)Window.DecorView.SystemUiVisibility;
uiOptions |= (int)SystemUiFlags.HideNavigation;
Window.DecorView.SystemUiVisibility = (StatusBarVisibility) SystemUiFlags.HideNavigation;
});
In Shared project. Into MainPage constructor (I put it after InitializeComponent() but I doubt it is necessary):
MessagingCenter.Send<Object>(this, "HideOsNavigationBar");
Related
I am trying to get a .NET Maui app up and running and it is working quite well so far - with one major problem: I cannot get it fixed that an Entry/Editor control stays above the keyboard and doesn't get overlapped.
I know there is an open issue and it is in the backlog, but the app seems unusable until this is fixed. There have been a couple of workarounds like
[GitHub] dotnet/maui issue 4792,
[GitHub] dotnet/maui issue 10662 (#1) and
[GitHub] dotnet/maui issue 10662 (#2)
but I cannot get them to work when registering as a handler. #1 doesn't do anything and #2 crashes when loading any view.
There is a solution on StackOverflow as well (Question 72536074) - unfortunately this method ignores the keyboard height.
To reproduce the problem the simplest code example would be any ContentPage with the following content:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="EntryIssueMaui.MainPage">
<ScrollView>
<Entry VerticalOptions="End" BackgroundColor="LightCoral" />
</ScrollView>
</ContentPage>
based on the default Maui template app.
It results in the Entry (red) not being pushed up in the ScrollView when the keyboard is enabled:
How can I implement the - I guess usually default feature - that the control is being pushed up to be still visible while considering the height of the keyboard (e.g. with/without autocompletion or emoji keyboard)?
Thanks in advance!
To solve this issue, you could obtain keyboard's frame via UIKeyboard.FrameEndUserInfoKey and calculate the height need to change.
NSValue result = (NSValue)args.Notification.UserInfo.ObjectForKey(new NSString(UIKeyboard.FrameEndUserInfoKey));
CGSize keyboardSize = result.RectangleFValue.Size;
private void Entry_Focused(object sender, FocusEventArgs e)
{
if (DeviceInfo.Current.Platform == DevicePlatform.iOS)
{
NFloat bottom;
try
{
UIWindow window = UIApplication.SharedApplication.Delegate.GetWindow();
bottom = window.SafeAreaInsets.Bottom;
}
catch
{
bottom = 0;
}
var heightChange = (keyboardSize.Height - bottom);
layout.TranslateTo(0, originalTranslationY.Value - heightChange, 50);
}
}
private void Entry_Unfocused(object sender, FocusEventArgs e)
{
if (DeviceInfo.Current.Platform == DevicePlatform.iOS)
{
layout.TranslateTo(0, 0, 50);
}
}
Hope it works for you.
As described in the title I am looking to add a ToolbarItem to my MainPage.xaml.cs in a Xamarin.Forms Project.
This is because I want an Actionbar on my Android App.
This to my knowledge is available on a NavigationPage.
I have not been able to set my Mainpage as a NavigationPage despite many attempts, it appears it will not let me set it as anything other than a ContentPage.
So far the best information I can find on this subject is here:
xamarin.forms not showing ToolbarItem
This however does not answer my question as it is relevant to App.xaml.cs not MainPage.xaml.cs
And my project is a multi-platform Xamarin.Forms for building apps apps for IOS and Android with Xamarin and Xamarin.Forms project.
Currently however I'm just focusing on Android in the shared C# project (MainPage.xaml.cs).
Thanks in Advance.
As Described in Wendy's answer the following code is required:
MainPage = new NavigationPage(new MainPage());
However she forgot the mention this code needs to be added to App.xaml.cs not MainPage.xaml.cs file.
This file is present in the C# Project for a Xamarin.Forms mobile app.
You can find it by clicking the drop down arrow in the 'Solution Explorer' on the 'App.xaml' file to find the 'App.xaml.cs' file.
If you can't find it type it in the search bar on the 'Solution Explorer'.
And edit the MainPage = new MainPage(); code in the file to MainPage = new NavigationPage(new MainPage());
The ToolbarItems needs a Navigation Page to show them up. So modify your MainPage wrapped by a navigation page:
App.xaml.cs:
public partial class App : Application
{
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new MainPage());
}
Screenshot:
I have the following set in my view code behind
NavigationPage.SetHasNavigationBar(this, false);
and I have it also in the XAML
NavigationPage.HasNavigationBar="False"
However the navigation panel is still displaying when navigating with Prism and the follow code:
await NavigationService.NavigateAsync("NavigationPage/RecipeListPage");
Navigating with the absolute method such as:
NavigationService.NavigateAsync(new System.Uri("http://www.RecipeDatabase/RecipeListPage", System.UriKind.Absolute));
Fixes this issue. Not sure why its needed. Also hiding with just the XAML code as well is sufficient.
Enjoy.
I just tried to create a new UWP App referencing: MonoGame.Framework.WindowsUniversal 3.6.0.1625, and Targeting Windows 10 Creators Update (10.0; Build 15063).
I think I did everything right to "bootstrap" a : Game from the SwapChainPanel:
I put <SwapChainPanel x:Name="swapChainPanel" /> in my Page
I put this in codebehind:
public sealed partial class MainPage : Page
{
readonly Game1 _game;
public MainPage()
{
this.InitializeComponent();
// Create the game.
var launchArguments = string.Empty;
_game = MonoGame.Framework.XamlGame<Game1>.Create(launchArguments, Window.Current.CoreWindow, swapChainPanel);
_game.Run();
}
}
And my Game1 : Game is just the same as Monogame templates.
When I start the application, there are no exceptions and the whole window hangs on the "UWP SplashScreen" (when it shows you the icon of your app) and nothing happens. My Draw method just clears the screen with red, just to see it working, but it doesn't.
Am I missing something?
I attached a very simple project to show that.
Solved, the problem was calling: _game.Run();.
By reading the source code on Github, I saw that the method:
static public T Create(string launchParameters, CoreWindow window, SwapChainPanel swapChainPanel)
already called Run:
// Start running the game.
game.Run(GameRunBehavior.Asynchronous);
By removing my call to the Run method, everything worked.
I'm using Monotouch to develop an app for the iPhone.
In my iPhone only app, I have an InputAccessoryView appear whenever the user selects a textfield. The accessory view provides buttons which aid the user (undo/redo etc).
It works fantastically on the simulator and on iPhone devices.
However, out of the blue, the Input Accessory View is not appearing on the iPad. I've made no changes to the code regarding the views; I've even rolled back to a version that I know displayed the accessory view correctly.
I was wondering if anyone else has come across this behaviour before / would know why this is happening?
EDIT
I've seen this accross all of my iphone projects running on the ipad. I made a fresh project which only contains 1 view, a UITextField and override the Input Accessory View and I'm still seeing nothing.
Code I'm using to test the override of the input view is:
public override UIView InputAccessoryView
{
get
{
UIView view = new UIView(new RectangleF(0,0,320,30));
view.BackgroundColor = UIColor.Blue;
return view;
}
}
Nothing too complex, on the iPhone just returns a blue bar above the keyboard.
I've reinstalled Mono, MonoDevelop, Monotouch and the iOS SDK multiple times to no avail. Apps that I've downloaded from the store still show the Input Accessory View, so I'm beginning to wonder if it's an issue with my Monotouch/iOS SDK combo? I'm using Monotouch 3.1.3 personal and 4.1 iOS SDK - version 2.6 of Mono. I'm going to try updating to version 2.8 of Mono.
The thing I don't understand is why it would work previously then all of a sudden just stop working?
When I'm deploying the code on the iPad, I'm selecting "Rebuild all", then uploading to the device. It doesn't matter if I pick either Release/Debug as a build, both yield the same result.
EDIT 2
If I subclass a UITextField and override the InputAccessoryView within that subclass, then the view appears on the iPad. This means that the InputAccessoryView which is being overriden in the View class isn't being assigned to the Textfield on the ipad.
EDIT 3
It would appear this is fixed in iOS 4.2 with Monotouch 3.2 !
My first suggestion is to reset the device in iTunes. You may have done so already, but just in case you did not, please do it first (since it's quick and easy to do).
If that didn't help: To identify if it is a problem with Monotouch and/or the iOS SDK could you repeat what you did above using only Cocoa Touch?
I.e., start a View-based app in XCode, add one UITextField in Interface Builder and connect it to the controller. Here is a corresponding Objective-C code to do it:
Instance variables in your controller (add to the #interface section in the <controllername>.h file):
IBOutlet UITextField *text;
UIView *accessory;
Hook up the UITextField in Interface Builder with the text outlet and then add the following implementation of viewDidLoad to the controller (the #implementation section in the <controllername>.m file):
- (void)viewDidLoad {
accessory = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
[accessory setBackgroundColor:[UIColor blueColor]];
[text setInputAccessoryView:accessory];
[super viewDidLoad];
}
If this displays the blue bar correctly, the problem is with the setup of Monotouch. If it does not, it is an issue with your device.
I had the same issue where a UITextView contained within a UIView would show the accessory bar on the simulator but not on the iPhone or iPad.
I'm doing some strange things with BeginFirstResponder to allow tapping anywhere in the larger parent area (containing a label and the text field) and activating the contained field and suspected this was involved. I added code in the parent UIView to override the InputAccessoryView and have it return the the value from the child UITextView and this fixed.
I suspect that Monotouch has an issue routing the event to the wrong object and my fix resolved it.
pseudo code:
public class ParentView : UIView
{
UILabel Label;
MyTextView Text;
/*Magic line here that fixed the problem */
public override UIView InputAccessoryView {get{return Text.InputAccessoryView;}}
}
public class MyTextView : UITextView
{
UIView Accessory;
public override UIView InputAccessoryView {get{return Accessory;}}
}
How are you showing your accessory view?
Can you try keeping a reference to the view?
Try this, and let me know if this fails:
public class Foo {
static UIView track;
}
And then when you create your view, stick it in that global:
Foo.track = new MyAccessoryView ()