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

时间:2018-08-13 17:19:51

标签: android android-layout android-studio android-drawable android-styles

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

有人有没有在主活动中使用计时器而不具有启动屏幕的经验吗?

因此,仅在加载主要活动之前执行启动屏幕。

我缺少设置步骤吗?

values-notnight / styles.xml

document.getElementById("<%=RadButton1.ClientID%>").removeAttribute("disabled");

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>

drawable-notnight / launch_screen.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-night / 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>

AndroidManifest.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>

1 个答案:

答案 0 :(得分:0)

您必须做的三件事

首先:白天,文件夹名称为values,晚上,文件夹名称为values-night。可相应绘制drawabledrawable-night

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

第三:在布局中使用ViewFlipper

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

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