android - Xamarin Forms - Android Splashscreen 也显示在主应用程序中
问题描述
我在我的应用程序中添加了一个启动画面
<item name="android:windowBackground">@drawable/splashScreen</item>
到MainTheme
我的应用程序。
启动画面在应用程序启动时正确显示,但在应用程序的所有页面中仍然作为背景。
我怎样才能避免这种行为?
这里有一个视频可以更好地展示这种行为。
谢谢!
解决方案
您需要至少有两个主题。一个用于启动屏幕,另一个用于您的应用程序的其余部分(您也可以为特定页面设置其他主题)。
在我的例子中,我有“splashscreen”用于启动屏幕,“AppTheme”用于应用程序的其余部分。
将启动主题定义为:
<style name="splashscreen" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@drawable/Zenon_Welcome_Screen</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsTranslucent">false</item>
<item name="android:windowIsFloating">false</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
和 AppTheme 为:
<style name="AppTheme" parent="AppTheme.Base">
</style>
<!-- App theme applied no matter what API -->
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
<item name="windowNoTitle">true</item>
<!--We will be using the toolbar so no need to show ActionBar-->
<item name="windowActionBar">false</item>
<!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette -->
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#c62828</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">#8e0000</item>
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="colorAccent">#8e0000</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
</style>
现在在您的主要活动中:
[Activity(Label = "AppName", Icon = "@drawable/icon", Theme = "@style/splashscreen", MainLauncher = true,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, ScreenOrientation = ScreenOrientation.Portrait,
LaunchMode = LaunchMode.SingleTask)]
public class MainActivity : FormsAppCompatActivity
现在在 onCreate 方法中,您需要切换主题,如下所示:
/// <summary>
/// On create.
/// </summary>
/// <param name="bundle">Bundle.</param>
protected override void OnCreate(Bundle bundle)
{
base.Window.RequestFeature(WindowFeatures.ActionBar);
// Name of the MainActivity theme we want to use for the app.
// Or we can use global::Android.Resource.Style.ThemeHoloLight / Theme Name.
base.SetTheme(Resource.Style.AppTheme);
base.OnCreate(bundle);
}
推荐阅读
- c# - Pop Async 删除内容页面资源标题
- python - 裁剪和保存 Tensorflow 对象检测 API 中的检测
- android - 如何在android studio中仅删除xlarge的布局?
- azure - Azure AD - 企业应用程序中缺少“Office 365 管理 API”
- certificate - https on amason EC2 与 OVH CDN
- flutter - 同意消息未显示
- python - 在numpy中加倍列表
- python - 如何“剪辑”matplotlib 颜色条?
- events - Fullcalendar 事件加载 ajax 日期结束看不到
- r - 在 phantomjs 会话中搜索元素或先提取源代码的区别?