问题描述
我定义了以下初始屏幕(splash.xml):
I have the following splash screen defined (splash.xml):
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<item android:drawable="@color/colorGold"/>
<item>
<bitmap
android:gravity="center"
android:src="@drawable/Banner2"/>
</item>
</layer-list>
这是style.xml:
This is the style.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">false</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name ="Theme.AppCompat.Light.NoActionBar" parent="ThemeOverlay.AppCompat"/>
<style name="SplashTheme" parent="AppTheme">
<item name="android:windowBackground">@drawable/splash</item>
</style>
</resources>
这是我的清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="OML_Android.OML_Android" android:installLocation="auto">
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="28" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE" />
<service android:name=".SignalRSrv" android:label="Messenger" android:enabled="true"></service>
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme">
<activity android:name=".activities.MainActivity"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
闪屏根本不显示,什么也不显示.我从这里关于stackoverflow的帖子中复制了初始屏幕xml,现在已经花了两天时间,并且取得了零进展.我想念什么?
The splash screen does not display at all, nothing. I copied the splash screen xml from a post here on stackoverflow and I've been at this for a couple of days now and have made zero progress. What am I missing?
*更新*
由于@Dipankar Baghel取得了进展,现在出现了启动屏幕,但是应用程序崩溃了,并显示unhandled exception
,我的活动代码是:
Made progress thanks to @Dipankar Baghel now get the splash screen, but the app crashes with unhandled exception
, my activity code is:
using System;
using Android.App;
using Android.OS;
using Android.Runtime;
using Android.Support.Design.Widget;
using Android.Support.V7.App;
using Android.Views;
using Android.Widget;
using Android.Content;
using Acr.UserDialogs;
namespace MyAndroidApp
{
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme.NoActionBar", MainLauncher = true, NoHistory = true)]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
// reset theme prior to loading layout
SetTheme(Resource.Style.AppTheme);
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.activity_main);
RequestedOrientation = Android.Content.PM.ScreenOrientation.Portrait;
Android.Widget.Button MyButton = FindViewById<Android.Widget.Button>(Resource.Id.button_ok);
UserDialogs.Init(this);
MyButton.Click += (sender, e) =>
{
Context context = this.ApplicationContext;
Intent intent = new Intent(this, typeof(Logon));
intent.SetFlags(ActivityFlags.NewTask);
StartActivity(intent);
Finish();
};
}
}
}
这是布局代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:src="@drawable/Banner2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/imageView1" />
<Button
android:text="Ok"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button_ok" />
</LinearLayout>
布局没有太多,但是我得到的错误是:
There's not much to the layout, but the error I'm getting is:
`无法实例化活动ComponentInfo {MyAndroid.MyAndroid/MyAndroid.MyAndroid.activities.activity_main}:
`Unable to instantiate activity ComponentInfo{MyAndroid.MyAndroid/MyAndroid.MyAndroid.activities.activity_main}:``
*更新*
更新的清单代码.
推荐答案
我认为您在这里有误会.
I think you have a misunderstanding here.
您在SplashTheme中拥有的"android:windowBackground"实际上不是Android Splash屏幕.启动应用程序后,将立即显示一个窗口.该窗口将一直显示,直到应用程序的主活动启动为止.
The "android:windowBackground" you had in SplashTheme is actualy not Android Splash screen. It is just a window will be displayed immediately after you launch your Application. This window will be displayed until the main Activity of application started.
通常,第一次启动应用程序(冷启动)时,您会看到此windowBackground.但是,如果您在冷启动后恢复或热启动应用程序,则可能看不到windowBackground.
Normally, you can see this windowBackground for the first time you launch your application (Cold start). But if you resume or Hot start application after Cold start you may not see the windowBackground.
有关更多详细信息,请参见下面的链接
For more detail please refer below link
https://developer.android.com/topic/performance/vitals/发射时间
这篇关于Android启动画面不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!