在Android夜间模式和白天模式主题之间如何切换? [英] How to switch between night-mode and day-mode themes on Android?

查看:607
本文介绍了在Android夜间模式和白天模式主题之间如何切换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有制造新闻的基础应用。我想设置夜景模式和白天模式下的主题。任何一个可以告诉我,我必须使用使用的设置(这我已经使用prefresnce)选择主题任何机构可以告诉我,或可安迪的一种提供这种类型的示例URL。

I have create news base Application . i want to set night mode and day mode theme . can any one tell me i have to use select theme using Setting (for this i have Used Prefresnce ) can any Body tell me or Can andy One Provide such type Example URL .

推荐答案

如果我没有记错,有一个在蜂窝样品有白天方式或夜间模式选项的例子。

If I remember correctly, there was an example in the Honeycomb Samples which has day mode or night mode option.

您应该能够从Android SDK管理器下载示例。

You should be able to download the Sample from the Android SDK Manager.

明白了。样品被称为的 HoneycombGallery

Got it. The sample is called HoneycombGallery

这是什么,他们做的要点:

And this is the gist of what they have done:

主题:

他们有两个简单的主题,在他们的 styles.xml

They have two simple themes in their styles.xml:

<style name="AppTheme.Light" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/ActionBar.Light</item>
    <item name="android:windowActionBarOverlay">true</item>
    <item name="listDragShadowBackground">@android:color/background_light</item>
    <item name="menuIconCamera">@drawable/ic_menu_camera_holo_light</item>
    <item name="menuIconToggle">@drawable/ic_menu_toggle_holo_light</item>
    <item name="menuIconShare">@drawable/ic_menu_share_holo_light</item>
</style>

<style name="AppTheme.Dark" parent="@android:style/Theme.Holo">
    <item name="android:actionBarStyle">@style/ActionBar.Dark</item>
    <item name="android:windowActionBarOverlay">true</item>
    <item name="listDragShadowBackground">@android:color/background_dark</item>
    <item name="menuIconCamera">@drawable/ic_menu_camera_holo_dark</item>
    <item name="menuIconToggle">@drawable/ic_menu_toggle_holo_dark</item>
    <item name="menuIconShare">@drawable/ic_menu_share_holo_dark</item>
</style>

菜单切换模式之间:

这是 main_menu.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/camera"
        android:title="Camera"
        android:icon="?attr/menuIconCamera"
        android:showAsAction="ifRoom" />
    <item android:id="@+id/toggleTitles"
        android:icon="?attr/menuIconToggle"
        android:title="Toggle Titles"
        android:showAsAction="ifRoom|withText" />
    <!-- Example of items in the overflow menu -->
    <item android:id="@+id/toggleTheme"
        android:title="Day/Night"
        android:showAsAction="never" />
    <item android:id="@+id/showDialog"
        android:title="Show a dialog"
        android:showAsAction="never" />
    <item android:id="@+id/showStandardNotification"
        android:title="Show a basic notification"
        android:showAsAction="never" />
    <item android:id="@+id/showCustomNotification"
        android:title="Show a custom notification"
        android:showAsAction="never" />
</menu>

和其余的是在完成了 MainActivity

这应该帮助您开始。祝你好运。 ; - )

This should help you get started. Good luck. ;-)

这篇关于在Android夜间模式和白天模式主题之间如何切换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆