gpt4 book ai didi

android - 如果我的手机处于浅色或深色模式,如何制作带有文本和背景颜色的 Android 启动画面?

转载 作者:行者123 更新时间:2023-12-03 15:55:13 25 4
gpt4 key购买 nike

我已经为此工作了一段时间,不幸的是,如果不使用图像,我无法达到预期的效果。我对 Stack Overflow 和几乎所有地方都进行了研究,但仍然没有找到可以做到这一点的解决方案。

我仍在尝试做的是:

  • 手机处于灯光模式 > 闪屏背景为白色,中间为黑色单词 ABC
  • 手机处于深色模式 > 闪屏背景为黑色,中间为白色单词 ABC

  • 这是我到目前为止所拥有的:

    SplashActivity.cs
    namespace Japanese.Droid
    {
    [Activity(Label = "Anki+", Theme = "@style/LaunchTheme", MainLauncher = true, NoHistory = true)]
    public class SplashActivity : Activity
    {

    样式.xaml
    <style name="LaunchTheme" parent="Theme.AppCompat">
    <item name="android:windowBackground">@drawable/splash_screen</item>
    <item name="android:navigationBarColor">#ffffff</item>
    </style>

    splash_screen.xaml
    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@android:color/white"/>
    <item>
    <bitmap android:src="@drawable/splash_logo"
    android:tileMode="disabled"
    android:gravity="center"
    android:layout_gravity="center"/>
    </item>
    </layer-list>

    splash_screen_night.xaml
    <?xml version="1.0" encoding="UTF-8" ?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@android:color/black"/>
    <item>
    <bitmap android:src="@drawable/splash_logo"
    android:tileMode="disabled"
    android:gravity="center"
    android:layout_gravity="center"/>
    </item>
    </layer-list>

    splash_activity
    using Android.App;
    using Android.Content;
    using Android.OS;
    using Android.Runtime;
    using Android.Support.V7.App;
    using Android.Views;

    namespace Test.Droid
    {
    [Activity(Label = "Test+", Theme = "@style/LaunchTheme", MainLauncher = true, NoHistory = true)]
    public class SplashActivity : Activity
    {

    public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState)
    {
    base.OnCreate(savedInstanceState, persistentState);

    //==================================== Code to hide the bottom 3 buttons on Android.
    int uiOptions = (int)Window.DecorView.SystemUiVisibility;
    uiOptions |= (int)SystemUiFlags.LowProfile;
    uiOptions |= (int)SystemUiFlags.Fullscreen;
    uiOptions |= (int)SystemUiFlags.HideNavigation;
    uiOptions |= (int)SystemUiFlags.ImmersiveSticky;
    Window.DecorView.SystemUiVisibility = (StatusBarVisibility)uiOptions;
    //===================================

    base.SetTheme(Resource.Style.MainTheme);
    Xamarin.Essentials.Platform.Init(this, savedInstanceState);
    }

    // Launches the startup task
    protected override void OnResume()
    {
    base.OnResume();

    //==================================== Code to hide the bottom 3 buttons on Android.
    int uiOptions = (int)Window.DecorView.SystemUiVisibility;
    uiOptions |= (int)SystemUiFlags.LowProfile;
    uiOptions |= (int)SystemUiFlags.Fullscreen;
    uiOptions |= (int)SystemUiFlags.HideNavigation;
    uiOptions |= (int)SystemUiFlags.ImmersiveSticky;
    Window.DecorView.SystemUiVisibility = (StatusBarVisibility)uiOptions;
    //===================================

    System.Threading.Tasks.Task startupWork = new System.Threading.Tasks.Task(() => { SimulateStartup(); });
    startupWork.Start();
    }


    // Simulates background work that happens behind the splash screen
    async void SimulateStartup()
    {
    await System.Threading.Tasks.Task.Delay(1000); // Simulate a bit of startup work.
    StartActivity(new Intent(Application.Context, typeof(MainActivity)));
    }

    public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
    {
    Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
    base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
    }

    public override void OnBackPressed() { }
    }
    }

    这使用图像,但我想用文本来做。

    有谁知道这样做的方法。我已经尽可能地对此进行了研究,向两个 Android 开发人员寻求帮助,但仍然没有人能在不使用图像的情况下提出一个简单的解决方案来做到这一点。

    是否可以仅使用文本和 不是 我的 Xamarin Android 应用程序的图像?

    最佳答案

    为了实现这一点,您需要在 Android 项目的 Layout 文件夹中创建一个 SplashScreen.xml。您还需要在两个文件夹中创建样式,values 和 values-night。

    您还需要一个单独的 SplashActivity.cs。我附上代码。

  • 闪屏.xml
      <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_vertical"
    android:background="#fff"
    android:id="@+id/splashview">
    <TextView
    android:id="@+id/txtAppVersion"
    android:text="Anki+"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginLeft="30dp"
    android:layout_marginBottom="30dp"
    android:textColor="#000"
    android:textSize="24sp"
    android:gravity="center_vertical"
    android:layout_centerHorizontal="true"/>
    </RelativeLayout>
  • 值文件夹中的 Styles.xml。

    <style name="MainTheme" parent="MainTheme.Base">
    <item name="android:textAllCaps">false</item>
    </style>

    <style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="windowActionModeOverlay">true</item>
    <item name="elevation">0dp</item>
    </style>

    <style name="LaunchTheme" parent="Theme.AppCompat">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowDisablePreview">true</item>
    </style>

  • values-night 文件夹中的 Styles.xml。

    <style name="MainTheme" parent="MainTheme.Base">
    <item name="android:textAllCaps">false</item>
    </style>

    <style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="windowActionModeOverlay">true</item>
    <item name="elevation">0dp</item>
    </style>

    <style name="LaunchTheme" parent="Theme.AppCompat">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowDisablePreview">true</item>
    </style>

  • SplashActivity.cs
    using System;
    using Android.App;
    using Android.Content;
    using Android.Content.Res;
    using Android.OS;
    using Android.Runtime;
    using Android.Views;
    using Android.Widget;
    using Plugin.CurrentActivity;

    namespace MyProject.Droid
    {
    [Activity(Label = "MyProject+", Theme = "@style/LaunchTheme",
    MainLauncher = true, NoHistory = true)]
    public class SplashActivity : Activity
    {

    public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState)
    {
    base.OnCreate(savedInstanceState, persistentState);

    //==================================== Code to hide the bottom 3 buttons on Android.
    int uiOptions = (int)Window.DecorView.SystemUiVisibility;
    uiOptions |= (int)SystemUiFlags.LowProfile;
    uiOptions |= (int)SystemUiFlags.Fullscreen;
    uiOptions |= (int)SystemUiFlags.HideNavigation;
    uiOptions |= (int)SystemUiFlags.ImmersiveSticky;
    Window.DecorView.SystemUiVisibility = (StatusBarVisibility)uiOptions;
    //===================================

    base.SetTheme(Resource.Style.MainTheme);
    Xamarin.Essentials.Platform.Init(this, savedInstanceState);
    }

    // Launches the startup task
    protected override void OnResume()
    {
    base.OnResume();
    SetContentView(Resource.Layout.SplashScreen);
    bool isDarkTheme;

    //var isDarkTheme = Preferences.Get("isDarkTheme", false);
    if (Build.VERSION.SdkInt >= BuildVersionCodes.Froyo)
    {
    var uiModeFlags = CrossCurrentActivity.Current.AppContext.Resources.Configuration.UiMode & UiMode.NightMask;
    if (uiModeFlags == UiMode.NightYes)
    isDarkTheme = true;
    else isDarkTheme = false;
    }
    else
    isDarkTheme = false;

    if (isDarkTheme)
    {
    FindViewById<RelativeLayout>(Resource.Id.splashview).SetBackgroundColor(Android.Graphics.Color.ParseColor("#000000"));
    FindViewById<TextView>(Resource.Id.txtAppVersion).SetTextColor(Android.Graphics.Color.ParseColor("#FFFFFF"));
    }
    else
    {
    FindViewById<RelativeLayout>(Resource.Id.splashview).SetBackgroundColor(Android.Graphics.Color.ParseColor("#FFFFFF"));
    FindViewById<TextView>(Resource.Id.txtAppVersion).SetTextColor(Android.Graphics.Color.ParseColor("#000000"));
    }

    // FindViewById<TextView>(Resource.Id.txtAppVersion).Text = $"Version {PackageManager.GetPackageInfo(PackageName, 0).VersionName}";

    //==================================== Code to hide the bottom 3 buttons on Android.
    int uiOptions = (int)Window.DecorView.SystemUiVisibility;
    uiOptions |= (int)SystemUiFlags.LowProfile;
    uiOptions |= (int)SystemUiFlags.Fullscreen;
    uiOptions |= (int)SystemUiFlags.HideNavigation;
    uiOptions |= (int)SystemUiFlags.ImmersiveSticky;
    Window.DecorView.SystemUiVisibility = (StatusBarVisibility)uiOptions;
    //===================================

    System.Threading.Tasks.Task startupWork = new System.Threading.Tasks.Task(() => { SimulateStartup(); });
    startupWork.Start();
    }

    // Simulates background work that happens behind the splash screen
    async void SimulateStartup()
    {
    await System.Threading.Tasks.Task.Delay(1000); // Simulate a bit of startup work.
    StartActivity(new Intent(Application.Context, typeof(MainActivity)));
    }

    public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
    {
    Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
    base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
    }

    public override void OnBackPressed() { }
    }
    }
  • 关于android - 如果我的手机处于浅色或深色模式,如何制作带有文本和背景颜色的 Android 启动画面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60465982/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com