gpt4 book ai didi

android - 基于一天中的时间的启动画面

转载 作者:行者123 更新时间:2023-11-29 02:26:46 25 4
gpt4 key购买 nike

是否可以根据一天中的不同时间设置不同的启动画面。我尝试创建 values-night/styles.xml 和 values-notnight/styles.xml 以及具有相同命名图像的 drawable-night 和 drawable-notnight,但它不会根据电话时间交替。

有没有人有过在主要 Activity 中不使用计时器而拥有不同启动屏幕的经验?

因此,仅在加载主要 Activity 之前才显示启动屏幕。

我是否缺少设置步骤?

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>

values-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>

最佳答案

你必须做的三件事

首先:对于白天,文件夹名称将是values,对于晚上,文件夹名称将是values-night。 Drawable相应的drawabledrawable-night

第二:使用 Theme.AppCompat.DayNight.DarkActionBar 作为父主题。

第三种:使用ViewFlipper在你的布局中

在你的代码中查找当前时间并检查预期时间:

  ViewFlipper vf = (ViewFlipper) findViewById( R.id.viewFlipper );
if (mCurrentTime == //whatever time you want) {
vf.showNext();
}

关于android - 基于一天中的时间的启动画面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51827539/

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