Android UNO UWP 项目的启动画面
Android splash screen for UNO UWP project
我正在尝试为我的 UNO 解决方案的 Android 部分实现启动画面。我可以让启动画面出现,等待几秒钟,但在导航到主页后,我在 app.cs
中收到以下异常
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
#if DEBUG
if (System.Diagnostics.Debugger.IsAttached)
{
// this.DebugSettings.EnableFrameRateCounter = true;
}
#endif
Frame rootFrame = Windows.UI.Xaml.Window.Current.Content as Frame;
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame(); <<<<< exception
未处理的异常:
Java.Lang.NullPointerException: 尝试在空对象引用上调用虚拟方法 'android.content.res.Resources android.content.Context.getResources()'
堆栈跟踪非常简单:
0x25 in Uno1.App.OnLaunched at C:\Users\pjsta\Documents\Visual Studio 2017\Projects\Uno1\Uno1\Uno1.Shared\App.xaml.cs:55,17 C#
解决方案的相关部分是
1. 我在 Android 项目
中的新 SplashActivity
[Activity(Label = "SplashScreen", MainLauncher = true, Theme = "@style/Theme.SplashActivity")]
public class SplashActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
System.Threading.Thread.Sleep(1000);
StartActivity(typeof(MainActivity));
}
}
修改 MainActivity 使其不是 MainLauncher
[Activity(
主启动器=假,
配置更改 = ConfigChanges.Orientation |
ConfigChanges.ScreenSize,
WindowSoftInputMode = SoftInput.AdjustPan | SoftInput.StateHidden )]
public class 主要Activity : Windows.UI.Xaml.ApplicationActivity
{
}
启动画面的相关样式加载成功。将 MainActivity 切换回 MainLauncher=true 可以工作,尽管没有启动画面。
我是 Xamarin 和 Android 开发的新手,但擅长 UWP。有人有什么想法吗?
从异常来看,听起来像是在调用 new Frame()
时,使用 null Context 调用了基本的本机构造函数。这可能是因为 Uno 期望 ApplicationActivity
为 运行,因为 MainLauncher=true。从 Uno.UI.BaseActivity
继承您的 SplashActivity
class 可能会解决错误。
在 Android 上显示启动画面的更好方法是修改主题,而不是创建单独的 activity。我将使用 Uno Gallery app as an example.
在您的 Android 头的 Resources/drawable 文件夹中创建一个名为 splash.xml 的文件。在这里定义启动画面的视觉外观。
打开 Resources/values/Styles.xml 文件。在 'AppTheme' 样式中添加以下行:
<item name="android:windowBackground">@drawable/splash</item>
希望对您有所帮助。另外,请将有关 Uno Platform 的问题标记为 'uno-platform'('uno' 标记指的是 OpenOffice 组件模型)。
我正在尝试为我的 UNO 解决方案的 Android 部分实现启动画面。我可以让启动画面出现,等待几秒钟,但在导航到主页后,我在 app.cs
中收到以下异常protected override void OnLaunched(LaunchActivatedEventArgs e) { #if DEBUG if (System.Diagnostics.Debugger.IsAttached) { // this.DebugSettings.EnableFrameRateCounter = true; } #endif Frame rootFrame = Windows.UI.Xaml.Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); <<<<< exception
未处理的异常: Java.Lang.NullPointerException: 尝试在空对象引用上调用虚拟方法 'android.content.res.Resources android.content.Context.getResources()'
堆栈跟踪非常简单:
0x25 in Uno1.App.OnLaunched at C:\Users\pjsta\Documents\Visual Studio 2017\Projects\Uno1\Uno1\Uno1.Shared\App.xaml.cs:55,17 C#
解决方案的相关部分是 1. 我在 Android 项目
中的新 SplashActivity [Activity(Label = "SplashScreen", MainLauncher = true, Theme = "@style/Theme.SplashActivity")]
public class SplashActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
System.Threading.Thread.Sleep(1000);
StartActivity(typeof(MainActivity));
}
}
修改 MainActivity 使其不是 MainLauncher
[Activity( 主启动器=假, 配置更改 = ConfigChanges.Orientation | ConfigChanges.ScreenSize, WindowSoftInputMode = SoftInput.AdjustPan | SoftInput.StateHidden )]
public class 主要Activity : Windows.UI.Xaml.ApplicationActivity { }
启动画面的相关样式加载成功。将 MainActivity 切换回 MainLauncher=true 可以工作,尽管没有启动画面。 我是 Xamarin 和 Android 开发的新手,但擅长 UWP。有人有什么想法吗?
从异常来看,听起来像是在调用 new Frame()
时,使用 null Context 调用了基本的本机构造函数。这可能是因为 Uno 期望 ApplicationActivity
为 运行,因为 MainLauncher=true。从 Uno.UI.BaseActivity
继承您的 SplashActivity
class 可能会解决错误。
在 Android 上显示启动画面的更好方法是修改主题,而不是创建单独的 activity。我将使用 Uno Gallery app as an example.
在您的 Android 头的 Resources/drawable 文件夹中创建一个名为 splash.xml 的文件。在这里定义启动画面的视觉外观。
打开 Resources/values/Styles.xml 文件。在 'AppTheme' 样式中添加以下行:
<item name="android:windowBackground">@drawable/splash</item>
希望对您有所帮助。另外,请将有关 Uno Platform 的问题标记为 'uno-platform'('uno' 标记指的是 OpenOffice 组件模型)。