Im developing an application using Xamarin forms for my android and iOS application. Currently when the application is being launched , a white screen is shown before my SplashScreen. How can we remove the white screen and shows directly the splash screen ?
App.xaml.cs
MainPage = new NavigationPage(new SplashScreen());
MainActivity.cs
{
[Activity(Label = "testApp", Icon = "#mipmap/icon", Theme = "#style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize )]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity, ActivityCompat.IOnRequestPermissionsResultCallback
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.SetTheme(Resource.Style.MainTheme);
base.OnCreate(savedInstanceState);
}
}
Android 12 doesn't allow an additional activity to act as a splash screen, so the link above is way out of date. The solution at the following link will enable a splash screen for any Xamarin.Android app. https://github.com/gmck/XamarinBasicSplashScreen.
The following is a link to the official android docs https://developer.android.com/develop/ui/views/launch/splash-screen
Related
I'm trying to change my app's splash screen into a custom image, I haven't found a solution that solved it for me ... I will be more than happy if someone will be able to solve it.
Thanks
I'm using Xamarin iOS on Windows Visual Studio
You could consider adding a Page to your Forms project as a Splash Page.
like
public App()
{
InitializeComponent();
MainPage = new SplashPage();
}
Then add a delay in SplashPage to jump to MainPage.
public SplashPage()
{
InitializeComponent();
}
protected override void OnAppearing()
{
base.OnAppearing();
Task.Run(async ()=> {
await Task.Delay(3000);
Device.BeginInvokeOnMainThread(()=> { App.Current.MainPage = new MainPage();});
});
}
I have an application that looks good in portrait mode but doesn't look good in landscape mode.
Is there any way within forms or through custom renderers that I can set the application so that it always sets itself into portrait mode?
Not sure if this helps, but I am using Xamarin Essentials, just in case there's a way to do it with the functionality that Essentials offers.
Device screen orientation in xamarin is usually configured from Host(Android/iOS) project.
On iOS, device orientation is configured for applications using the Info.plist file.
On Android, open MainActivity.cs and set the orientation using the attribute decorating the MainActivity class:
namespace MyRotatingApp.Droid
{
[Activity (Label = "MyRotatingApp.Droid", Icon = "#drawable/icon", Theme = "#style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, ScreenOrientation = ScreenOrientation.Landscape)] //This is what controls orientation
public class MainActivity : FormsAppCompatActivity
{
}
}
For more info, you can check this link
Look for this one in android
Activity(ScreenOrientation = ScreenOrientation.Portrait
In android MainActivity:
namespace Namespace.Droid
{
[Activity(ScreenOrientation = ScreenOrientation.Portrait , ...]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
...
In Ios Info.pList:
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
</array>
make sure that only the portrait orientation remains
I'm trying to use project specific Android drawables for a ToolbarItem. Because of the framework structure I use it appears as if my project specific drawables don't exist.
I created a project where I have the following structure:
Project diagram
The Project.Android MainActivity inherits from a FrameworkMainActivity. The FrameworkMainActivity is responsible for calling the OnCreate method. The Xamarin.Forms.Application is acquired through an abstract method.
public abstract class FrameworkMainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
this.LoadApplication(this.GetApp());
}
protected abstract Xamarin.Forms.Application GetApp();
}
In the Framework.Xamarin.Forms project I have a MasterDetailPage that adds a demo toolbar item which uses an icon with source: 'demo.png'
public DemoMasterDetailPage()
{
this.Master = new DemoMenuPage();
this.Detail = new NavigationPage(new DemoContentPage());
this.ToolbarItems.Add(new ToolbarItem()
{
Icon = "demo.png",
Text = "Demo",
});
}
The ToolbarItem icon has to be project specific so I can't place it in my Framework. This is not possible because when I place my image in Project.Android > Resources > drawable folder the I get the following output:
[0:] Could not load image named: {0}: demo.png
When I place the image in the Framework.Android > Resources > drawable folder the ToolbarItem works perfectly and shows my icon correctly.
Can someone tell me what I'm doing wrong or how I can workaround the issue?
XF Version: 2.4.0.282
I am trying to change the color of a toolbar in a Xamarin.Forms application. I used this to change the color:
MainPage = new NavigationPage(new StartPage())
{
BarBackgroundColor = Color.FromHex("#15315A"),
BarTextColor = Color.FromHex("#F3F9F5")
};
This works successfully on iOS, but on Android the Toolbar is just white. I tried to change the styles colors, and defined a Toolbar.axml with no luck either. I posted the pictures below of what I am seeing. Anyone know what I could be doing wrong?
There was a fairly good answer on this post on the xamarin developer forums. Basically there's a couple of options to get this to work, these are:
An Appearance which works globally.
Or using a custom renderer.
[assembly: ExportRenderer(typeof(TabbedPage), typeof(TabbedPageCustom))]
namespace MobileCRM.iOS
{
public class TabbedPageCustom : TabbedRenderer
{
public TabbedPageCustom ()
{
TabBar.TintColor = MonoTouch.UIKit.UIColor.Black;
TabBar.BarTintColor = MonoTouch.UIKit.UIColor.Blue;
TabBar.BackgroundColor = MonoTouch.UIKit.UIColor.Green;
}
}
}
Hello there I have an app which is compatible with Phone/Tablet and my TV Android Box .
However this app is not compatible with my Android Smart TV itself , like when i go to google play (which is Alpha) i get the text saying that the app is not compatible with the device.
I did some checks and I found that the app's menifest should mention that this is a LEANBACK_LAUNCHER, which I did like the following code:
[Activity(Label = "Afaq.IPTV", Icon = "#drawable/icon", MainLauncher = true,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
[IntentFilter(new[] {"android.intent.action.MAIN"}, AutoVerify = true,
Categories = new[] {"android.intent.category.LEANBACK_LAUNCHER"})]
public class MainActivity : FormsApplicationActivity
{...
So am I missing something ? has anyone succeeded with this before ?
I found the solution
In the mainActivity you start the class the way I did in the Quesiton
[Activity(Label = "Afaq.IPTV", Icon = "#drawable/icon", MainLauncher = true,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
[IntentFilter(new[] { Intent.ActionMain }, Categories = new[] {Intent.CategoryLauncher,Intent.CategoryLeanbackLauncher})]
public class MainActivity : FormsApplicationActivity
{...
In the manifest you have to add the following
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
After adding this line you will have an app that is available on Google Play store from your TV. However, if you have only this in the manifest then your app is not compatible with your touch screen devices (e.g. phones and tablets). Google this problem and you might find something useful which would solve this problem. My guess is by having another Activity that is for phones .