Java Code Examples for android.support.v7.app.AppCompatDelegate#getDefaultNightMode()
The following examples show how to use
android.support.v7.app.AppCompatDelegate#getDefaultNightMode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Canvas.java From Google-AAD-CheatSheet with MIT License | 6 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.night_mode) { // Get the night mode state of the app. int nightMode = AppCompatDelegate.getDefaultNightMode(); //Set the theme mode for the restarted activity if (nightMode == AppCompatDelegate.MODE_NIGHT_YES) { AppCompatDelegate.setDefaultNightMode (AppCompatDelegate.MODE_NIGHT_NO); } else { AppCompatDelegate.setDefaultNightMode (AppCompatDelegate.MODE_NIGHT_YES); } // Recreate the activity for the theme change to take effect. recreate(); } return super.onOptionsItemSelected(item); }
Example 2
Source File: MainActivity.java From styT with Apache License 2.0 | 6 votes |
@Override public boolean onPrepareOptionsMenu(Menu menu) { switch (AppCompatDelegate.getDefaultNightMode()) { case AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM: menu.findItem(R.id.menu_night_mode_system).setChecked(true); break; case AppCompatDelegate.MODE_NIGHT_AUTO: menu.findItem(R.id.menu_night_mode_auto).setChecked(true); break; case AppCompatDelegate.MODE_NIGHT_YES: menu.findItem(R.id.menu_night_mode_night).setChecked(true); break; case AppCompatDelegate.MODE_NIGHT_NO: menu.findItem(R.id.menu_night_mode_day).setChecked(true); break; } return true; }
Example 3
Source File: SettingActivity.java From Ency with Apache License 2.0 | 6 votes |
private void goBack() { int a = sharePrefManager.getLocalMode(); int b = AppCompatDelegate.getDefaultNightMode(); boolean c = sharePrefManager.getLocalProvincialTrafficPatterns(); boolean d = sharePrefManager.getProvincialTrafficPattern(); if(c != d){ RxBus.getInstance().post(1001); sharePrefManager.setLocalProvincialTrafficPatterns(d); } if (a != b) { sharePrefManager.setLocalMode(AppCompatDelegate.getDefaultNightMode()); RxBus.getInstance().post(1000); Intent intent = new Intent(mContext, MainActivity.class); startActivity(intent); overridePendingTransition(R.anim.open_enter, R.anim.open_exit); } finish(); }
Example 4
Source File: MainActivity.java From cheesesquare with Apache License 2.0 | 6 votes |
@Override public boolean onPrepareOptionsMenu(Menu menu) { switch (AppCompatDelegate.getDefaultNightMode()) { case AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM: menu.findItem(R.id.menu_night_mode_system).setChecked(true); break; case AppCompatDelegate.MODE_NIGHT_AUTO: menu.findItem(R.id.menu_night_mode_auto).setChecked(true); break; case AppCompatDelegate.MODE_NIGHT_YES: menu.findItem(R.id.menu_night_mode_night).setChecked(true); break; case AppCompatDelegate.MODE_NIGHT_NO: menu.findItem(R.id.menu_night_mode_day).setChecked(true); break; } return true; }
Example 5
Source File: MainActivity.java From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main_menu, menu); int nightMode = AppCompatDelegate.getDefaultNightMode(); if (nightMode == AppCompatDelegate.MODE_NIGHT_YES){ menu.findItem(R.id.night_mode).setTitle(R.string.day_mode); } else{ menu.findItem(R.id.night_mode).setTitle(R.string.night_mode); } return true; }
Example 6
Source File: MainActivity.java From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 | 5 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.night_mode){ int nightMode = AppCompatDelegate.getDefaultNightMode(); if (nightMode == AppCompatDelegate.MODE_NIGHT_YES){ AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); } else { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); } recreate(); } return true; }
Example 7
Source File: MainActivity.java From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main_menu, menu); int nightMode = AppCompatDelegate.getDefaultNightMode(); if (nightMode == AppCompatDelegate.MODE_NIGHT_YES){ menu.findItem(R.id.night_mode).setTitle(R.string.day_mode); } else{ menu.findItem(R.id.night_mode).setTitle(R.string.night_mode); } return true; }
Example 8
Source File: MainActivity.java From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 | 5 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.night_mode){ int nightMode = AppCompatDelegate.getDefaultNightMode(); if (nightMode == AppCompatDelegate.MODE_NIGHT_YES){ AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); } else { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); } recreate(); } return true; }
Example 9
Source File: MainActivity.java From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main_menu, menu); int nightMode = AppCompatDelegate.getDefaultNightMode(); if (nightMode == AppCompatDelegate.MODE_NIGHT_YES){ menu.findItem(R.id.night_mode).setTitle(R.string.day_mode); } else{ menu.findItem(R.id.night_mode).setTitle(R.string.night_mode); } return true; }
Example 10
Source File: MainActivity.java From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 | 5 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.night_mode){ int nightMode = AppCompatDelegate.getDefaultNightMode(); if (nightMode == AppCompatDelegate.MODE_NIGHT_YES){ AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); } else { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); } recreate(); } return true; }
Example 11
Source File: MainActivity.java From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main_menu, menu); int nightMode = AppCompatDelegate.getDefaultNightMode(); if (nightMode == AppCompatDelegate.MODE_NIGHT_YES){ menu.findItem(R.id.night_mode).setTitle(R.string.day_mode); } else{ menu.findItem(R.id.night_mode).setTitle(R.string.night_mode); } return true; }
Example 12
Source File: MainActivity.java From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 | 5 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.night_mode){ int nightMode = AppCompatDelegate.getDefaultNightMode(); if (nightMode == AppCompatDelegate.MODE_NIGHT_YES){ AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); } else { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); } recreate(); } return true; }
Example 13
Source File: MainActivity.java From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main_menu, menu); int nightMode = AppCompatDelegate.getDefaultNightMode(); if (nightMode == AppCompatDelegate.MODE_NIGHT_YES) { menu.findItem(R.id.night_mode).setTitle(R.string.day_mode); } else { menu.findItem(R.id.night_mode).setTitle(R.string.night_mode); } return true; }
Example 14
Source File: MainActivity.java From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 | 5 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.night_mode) { int nightMode = AppCompatDelegate.getDefaultNightMode(); if (nightMode == AppCompatDelegate.MODE_NIGHT_YES) { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); } else { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); } recreate(); } return true; }
Example 15
Source File: MeshengerActivity.java From meshenger-android with GNU General Public License v3.0 | 4 votes |
private boolean darkModeEnabled() { return (AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES); }
Example 16
Source File: ThemeSwitcher.java From graphhopper-navigation-android with MIT License | 4 votes |
/** * Returns true if the current UI_MODE_NIGHT is undefined, false otherwise. */ private static boolean isNightModeFollowSystem() { int nightMode = AppCompatDelegate.getDefaultNightMode(); return nightMode == AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; }