Last active
July 28, 2016 01:23
-
-
Save albeee/f13e5bf8c565f1e0a49249c51500c551 to your computer and use it in GitHub Desktop.
Android Night Mode - themes.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- ========================== --> | |
<!-- Base App Theme --> | |
<!-- ========================== --> | |
<style name="AppTheme.Base" parent="Theme.AppCompat.NoActionBar"> | |
<item name="android:windowNoTitle">true</item> | |
<item name="windowActionBar">false</item> | |
... | |
</style> | |
<!-- ========================== --> | |
<!-- Regular or Light App Theme --> | |
<!-- ========================== --> | |
<style name="AppTheme.Light" parent="AppTheme.Base"> | |
<item name="colorPrimary">@color/actionbar_background_color</item> | |
<item name="colorPrimaryDark">@color/statusbar_bg_color_filter_none</item> | |
... | |
</style> | |
<!-- ========================== --> | |
<!-- Night or Dark App Theme --> | |
<!-- ========================== --> | |
<style name="AppTheme.Dark" parent="AppTheme.Base"> | |
<item name="colorPrimary">@color/dark_action_bar_color</item> | |
<item name="colorPrimaryDark">@color/dark_status_bar_color</item> | |
... | |
</style> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class ThemeUtils { | |
private static int mAppTheme; | |
public static int getAppTheme(){ | |
mAppTheme = isNightMode() ? R.style.Apptheme_Dark : R.style.Apptheme_Light; | |
return mAppTheme; | |
} | |
public static boolean isNightMode(){ | |
// TODO - Create a time difference logic to detect the daylight and nightmode | |
return false; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends Activity { | |
public void onCreate(Bundle saveInstance) { | |
// set the daylight or night theme here | |
setTheme(Utils.getAppTheme()); | |
// super activity constructor | |
super.onCreate(saveInstance); | |
// set the content display view or layout | |
setContentView(R.layout.activity_main); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<style name="MyTheme" parent="Theme.AppCompat.DayNight"> | |
<!-- do something --> | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment