我的Android手机如何决定在亮或暗主题之间切换启动画面?

问题描述 投票:0回答:1

这是我为应用程序准备的代码。它可以在明暗之间正确切换,但是它是如何做到的呢?在样式中,我看不到任何关于splash_screen_night的信息,但似乎已被调用。

splash_activity.cs

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

值文件夹中的mainThemeStyle.xaml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="launcher_background">#000000</color>

    <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="MainTheme.Splash" parent ="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowBackground">@drawable/splash_screen</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:navigationBarColor">#ffffff</item>
    </style>

    <style name="LaunchTheme" parent="MainTheme">
        <item name="android:windowBackground">@drawable/splash_screen</item>
        <item name="android:navigationBarColor">#ffffff</item>
    </style>
</resources>

values-night文件夹中的styles.xaml

<?xml version="1.0" encoding="UTF-8" ?>
<resources>
    <style name="LaunchTheme" parent="Theme.AppCompat">
        <item name="android:windowBackground">@drawable/splash_screen_night</item>
        <item name="android:navigationBarColor">#000000</item>
    </style>
</resources>

可绘制文件夹中的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>

androidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="000401" android:versionName="0.4.2 beta 3" package="com.test.test">
    <uses-sdk android:minSdkVersion="24" android:targetSdkVersion="28" />
    <application android:icon="@mipmap/ic_launcher" android:label="Test"></application>
</manifest>
android android-studio xamarin xamarin.android
1个回答
0
投票

通常在manifest中提到主题名称。查看清单文件。

有两个选项,或者在app属性中添加主题以将主题应用于每个屏幕,或者将主题添加到每个屏幕的活动中。

<manifest ... >
    <application android:theme="@style/Theme.AppCompat" ... >
    </application>
</manifest>

<manifest ... >
    <application ... >
        <activity android:theme="@style/Theme.AppCompat.Light" ... >
        </activity>
    </application>
</manifest>
© www.soinside.com 2019 - 2024. All rights reserved.