【发布时间】:2018-08-13 17:19:50
【问题描述】:
是否可以根据一天中的时间有不同的启动画面。我尝试创建 values-night/styles.xml 和 values-notnight/styles.xml 以及具有相同命名图像的 drawable-night 和 drawable-notnight,但它不会根据手机的时间交替。
有没有人有过在主要活动中不使用计时器而拥有不同启动屏幕的经验?
因此,仅在加载主要活动之前执行启动屏幕。
我是否缺少设置步骤?
values-notnight/styles.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>
<item name="android:windowBackground">@drawable/metalic</item>
</style>
<style name="AppTheme.Launcher">
<item name="android:windowBackground">@drawable/launch_screen</item>
<!-- Optional, on Android 5+ you can modify the colorPrimaryDark color to match the windowBackground color for further branding-->
<!-- <item name="colorPrimaryDark">@android:color/white</item> -->
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
值-notnight/styles.xml
<!-- 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>
<item name="android:windowBackground">@drawable/carbon</item>
</style>
<style name="AppTheme.Launcher">
<item name="android:windowBackground">@drawable/launch_screen</item>
<!-- Optional, on Android 5+ you can modify the colorPrimaryDark color to match the windowBackground color for further branding-->
<!-- <item name="colorPrimaryDark">@android:color/white</item> -->
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
drawable-notnight/launch_screen.xml
<!-- The background color, preferably the same as your normal theme -->
<item android:drawable="@drawable/carbon"/>
<!-- Your product logo - 144dp color version of your app icon -->
<item>
<bitmap
android:src="@drawable/logo"
android:gravity="center"
android:scaleGravity="center_vertical|center_horizontal"
android:scaleHeight="60%"
android:scaleWidth="60%"/>
</item>
drawable-night/launch_screen.xml
<!-- The background color, preferably the same as your normal theme -->
<item android:drawable="@drawable/metalic"/>
<!-- Your product logo - 144dp color version of your app icon -->
<item>
<bitmap
android:src="@drawable/logo"
android:gravity="center"
android:scaleGravity="center_vertical|center_horizontal"
android:scaleHeight="60%"
android:scaleWidth="60%"/>
</item>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.root.myapplication">
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera" />
<application
android:allowBackup="true"
android:icon="@drawable/tech"
android:label="@string/app_name"
android:roundIcon="@drawable/tech"
android:supportsRtl="true"
android:theme="@style/AppTheme.Launcher">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.Launcher">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
【问题讨论】:
-
如果您正确地从手机中获取时间,当然您可以根据该信息启动不同的启动画面。例如,通过定义具有相应布局的单独 Splash 类
-
发布您的代码。
-
我添加了代码,目前它默认为drawable-notnight代码,即使我手机上的时间已手动设置为23:46。
-
我的清单需要额外的权限吗?
标签: android android-layout android-studio android-drawable android-styles