本文整理了Java中android.support.v7.app.AppCompatDelegate.setDefaultNightMode()
方法的一些代码示例,展示了AppCompatDelegate.setDefaultNightMode()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AppCompatDelegate.setDefaultNightMode()
方法的具体详情如下:
包路径:android.support.v7.app.AppCompatDelegate
类名称:AppCompatDelegate
方法名:setDefaultNightMode
暂无
代码示例来源:origin: chrisbanes/cheesesquare
private void setNightMode(@AppCompatDelegate.NightMode int nightMode) {
AppCompatDelegate.setDefaultNightMode(nightMode);
if (Build.VERSION.SDK_INT >= 11) {
recreate();
}
}
代码示例来源:origin: medyo/android-about-page
void simulateDayNight(int currentSetting) {
final int DAY = 0;
final int NIGHT = 1;
final int FOLLOW_SYSTEM = 3;
int currentNightMode = getResources().getConfiguration().uiMode
& Configuration.UI_MODE_NIGHT_MASK;
if (currentSetting == DAY && currentNightMode != Configuration.UI_MODE_NIGHT_NO) {
AppCompatDelegate.setDefaultNightMode(
AppCompatDelegate.MODE_NIGHT_NO);
} else if (currentSetting == NIGHT && currentNightMode != Configuration.UI_MODE_NIGHT_YES) {
AppCompatDelegate.setDefaultNightMode(
AppCompatDelegate.MODE_NIGHT_YES);
} else if (currentSetting == FOLLOW_SYSTEM) {
AppCompatDelegate.setDefaultNightMode(
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
}
}
}
代码示例来源:origin: smuyyh/BookReader
protected void initNightMode() {
boolean isNight = SharedPreferencesUtil.getInstance().getBoolean(Constant.ISNIGHT, false);
LogUtils.d("isNight=" + isNight);
if (isNight) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
} else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
}
代码示例来源:origin: smuyyh/BookReader
@Override
protected void onResume() {
super.onResume();
if (SharedPreferencesUtil.getInstance().getBoolean(Constant.ISNIGHT, false) != mNowMode) {
if (SharedPreferencesUtil.getInstance().getBoolean(Constant.ISNIGHT, false)) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
} else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
recreate();
}
}
代码示例来源:origin: hidroh/materialistic
private void onThemeChanged(int key) {
if (key == R.string.pref_daynight_auto) {
AppCompatDelegate.setDefaultNightMode(Preferences.Theme.getAutoDayNightMode(this));
}
if (mResumed) {
AppUtils.restart(this, true);
} else {
mPendingThemeChanged = true;
}
}
代码示例来源:origin: HotBitmapGG/bilibili-android-client
/**
* 日夜间模式切换
*/
private void switchNightMode() {
boolean isNight = PreferenceUtil.getBoolean(ConstantUtil.SWITCH_MODE_KEY, false);
if (isNight) {
// 日间模式
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
PreferenceUtil.putBoolean(ConstantUtil.SWITCH_MODE_KEY, false);
} else {
// 夜间模式
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
PreferenceUtil.putBoolean(ConstantUtil.SWITCH_MODE_KEY, true);
}
recreate();
}
代码示例来源:origin: iMeiji/Toutiao
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
settingUtil.setIsNightMode(true);
} else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
settingUtil.setIsNightMode(false);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
} else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
代码示例来源:origin: north2016/T-MVP
@TimeLog
public void onCreate() {
super.onCreate();
mApp = this;
Realm.init(this);
SpUtil.init(this);
AppCompatDelegate.setDefaultNightMode(SpUtil.isNight() ? AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO);
store = new Stack<>();
registerActivityLifecycleCallbacks(new SwitchBackgroundCallbacks());
}
代码示例来源:origin: north2016/T-MVP
public void reload() {
AppCompatDelegate.setDefaultNightMode(SpUtil.isNight() ? AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO);
getWindow().setWindowAnimations(R.style.WindowAnimationFadeInOut);
recreate();
}
代码示例来源:origin: smuyyh/BookReader
private void changedMode(boolean isNight, int position) {
SharedPreferencesUtil.getInstance().putBoolean(Constant.ISNIGHT, isNight);
AppCompatDelegate.setDefaultNightMode(isNight ? AppCompatDelegate.MODE_NIGHT_YES
: AppCompatDelegate.MODE_NIGHT_NO);
if (position >= 0) {
curTheme = position;
} else {
curTheme = SettingManager.getInstance().getReadTheme();
}
gvAdapter.select(curTheme);
mPageWidget.setTheme(isNight ? ThemeManager.NIGHT : curTheme);
mPageWidget.setTextColor(ContextCompat.getColor(mContext, isNight ? R.color.chapter_content_night : R.color.chapter_content_day),
ContextCompat.getColor(mContext, isNight ? R.color.chapter_title_night : R.color.chapter_title_day));
mTvBookReadMode.setText(getString(isNight ? R.string.book_read_mode_day_manual_setting
: R.string.book_read_mode_night_manual_setting));
Drawable drawable = ContextCompat.getDrawable(this, isNight ? R.drawable.ic_menu_mode_day_manual
: R.drawable.ic_menu_mode_night_manual);
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
mTvBookReadMode.setCompoundDrawables(null, drawable, null, null);
ThemeManager.setReaderTheme(curTheme, mRlBookReadRoot);
}
代码示例来源:origin: iMeiji/Toutiao
if (mode == Configuration.UI_MODE_NIGHT_YES) {
SettingUtil.getInstance().setIsNightMode(false);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
} else {
SettingUtil.getInstance().setIsNightMode(true);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
代码示例来源:origin: smuyyh/BookReader
if (SharedPreferencesUtil.getInstance().getBoolean(Constant.ISNIGHT, false)) {
SharedPreferencesUtil.getInstance().putBoolean(Constant.ISNIGHT, false);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
} else {
SharedPreferencesUtil.getInstance().putBoolean(Constant.ISNIGHT, true);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
代码示例来源:origin: hidroh/materialistic
@Override
public void onCreate() {
super.onCreate();
AppCompatDelegate.setDefaultNightMode(Preferences.Theme.getAutoDayNightMode(this));
AlgoliaClient.sSortByTime = Preferences.isSortByRecent(this);
mRefWatcher = LeakCanary.install(this);
if (BuildConfig.DEBUG) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectAll()
.penaltyFlashScreen()
.build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectAll()
.penaltyLog()
.build());
}
Preferences.migrate(this);
TYPE_FACE = FontCache.getInstance().get(this, Preferences.Theme.getTypeface(this));
AppUtils.registerAccountsUpdatedListener(this);
AdBlocker.init(this, Schedulers.io());
}
代码示例来源:origin: kaku2015/ColorfulNews
private void initDayNightMode() {
if (MyUtils.isNightMode()) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
} else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
}
代码示例来源:origin: fossasia/pslab-android
private void simulateDayNight(int currentSetting) {
final int DAY = 0;
final int NIGHT = 1;
final int FOLLOW_SYSTEM = 3;
int currentNightMode = getResources().getConfiguration().uiMode
& Configuration.UI_MODE_NIGHT_MASK;
if (currentSetting == DAY && currentNightMode != Configuration.UI_MODE_NIGHT_NO) {
AppCompatDelegate.setDefaultNightMode(
AppCompatDelegate.MODE_NIGHT_NO);
} else if (currentSetting == NIGHT && currentNightMode != Configuration.UI_MODE_NIGHT_YES) {
AppCompatDelegate.setDefaultNightMode(
AppCompatDelegate.MODE_NIGHT_YES);
} else if (currentSetting == FOLLOW_SYSTEM) {
AppCompatDelegate.setDefaultNightMode(
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
}
}
代码示例来源:origin: kaku2015/ColorfulNews
private void setNightOrDayMode() {
if (MyUtils.isNightMode()) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
initNightView();
mNightView.setBackgroundResource(R.color.night_mask);
} else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
}
代码示例来源:origin: DaxiaK/MyDiary
@Override
public void onCreate() {
super.onCreate();
//Use Fresco
Set<RequestListener> listeners = new HashSet<>();
listeners.add(new RequestLoggingListener());
ImagePipelineConfig config = ImagePipelineConfig.newBuilder(this)
.setRequestListeners(listeners)
.setDownsampleEnabled(true)
.build();
Fresco.initialize(this, config);
//To fix bug : spinner bg is dark when mode is night.
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
//Check password
if (SPFManager.getPassword(this).equals("")) {
hasPassword = false;
} else {
hasPassword = true;
}
//init Theme & language
initTheme();
setLocaleLanguage();
}
代码示例来源:origin: julian-klode/dns66
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
} else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
代码示例来源:origin: WallaceXiao/StockChart-MPAndroidChart
public void initDayNight(){
//初始化夜间模式
SharedPreferences sp = getSharedPreferences(Constants.SP_FILE,Context.MODE_PRIVATE);
if(sp.getBoolean(Constants.DAY_NIGHT_MODE,false)){
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
}else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
}
private void netWorkInit(){
代码示例来源:origin: zulip/zulip-android
/**
* Switches the current Day/Night mode to Night/Day mode
*
* @param nightMode which Mode {@link android.support.v7.app.AppCompatDelegate.NightMode}
*/
private void setNightMode(@AppCompatDelegate.NightMode int nightMode) {
AppCompatDelegate.setDefaultNightMode(nightMode);
if (Build.VERSION.SDK_INT >= 11) {
recreate();
}
}
内容来源于网络,如有侵权,请联系作者删除!