androidx.appcompat.app.AppCompatDelegate.setDefaultNightMode()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(173)

本文整理了Java中androidx.appcompat.app.AppCompatDelegate.setDefaultNightMode()方法的一些代码示例,展示了AppCompatDelegate.setDefaultNightMode()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AppCompatDelegate.setDefaultNightMode()方法的具体详情如下:
包路径:androidx.appcompat.app.AppCompatDelegate
类名称:AppCompatDelegate
方法名:setDefaultNightMode

AppCompatDelegate.setDefaultNightMode介绍

暂无

代码示例

代码示例来源:origin: y20k/transistor

private static void activateFollowSystemMode(Context context, Boolean notifyUser) {
  // save the new state
  saveNightModeState(context, AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
  // switch to Undefined Mode / Follow System
  AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
  // notify user
  if (notifyUser) {
    Toast.makeText(context, context.getText(R.string.toastmessage_theme_follow_system), Toast.LENGTH_LONG).show();
  }
}

代码示例来源:origin: y20k/transistor

private static void activateNightMode(Context context, Boolean notifyUser) {
  saveNightModeState(context, AppCompatDelegate.MODE_NIGHT_YES);
  // switch to Night Mode
  AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
  // notify user
  if (notifyUser) {
    Toast.makeText(context, context.getText(R.string.toastmessage_theme_night), Toast.LENGTH_LONG).show();
  }
}

代码示例来源:origin: 8enet/AppOpsX

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
 LangHelper.updateLanguage(this);
 super.onCreate(savedInstanceState);
 AppCompatDelegate.setDefaultNightMode(SpHelper.getThemeMode(this));
}

代码示例来源:origin: y20k/transistor

private static void activateDayMode(Context context, Boolean notifyUser) {
  // save the new state
  saveNightModeState(context, AppCompatDelegate.MODE_NIGHT_NO);
  // switch to Day Mode
  AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
  // notify user
  if (notifyUser) {
    Toast.makeText(context, context.getText(R.string.toastmessage_theme_day), Toast.LENGTH_LONG).show();
  }
}

代码示例来源:origin: PureWriter/about-page

@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
  if (menuItem.getItemId() == R.id.menu_night_mode) {
    menuItem.setChecked(!menuItem.isChecked());
    if (menuItem.isChecked()) {
      AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES);
    } else {
      AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO);
    }
    getDelegate().applyDayNight();
  }
  return true;
}

代码示例来源:origin: sschueller/peertube-android

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  // Set Night Mode
  SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
  AppCompatDelegate.setDefaultNightMode(sharedPref.getBoolean("pref_dark_mode", false) ?
      AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO);
  // Set theme
  setTheme(getResources().getIdentifier(
      sharedPref.getString(THEME_PREF_KEY, DEFAULT_THEME),
      "style",
      getPackageName())
  );
}

代码示例来源:origin: WireGuard/wireguard-android

@Override
  public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences, final String key) {
    if ("dark_theme".equals(key)) {
      final boolean darkMode = sharedPreferences.getBoolean(key, false);
      AppCompatDelegate.setDefaultNightMode(
          sharedPreferences.getBoolean(key, false) ?
              AppCompatDelegate.MODE_NIGHT_YES :
              AppCompatDelegate.MODE_NIGHT_NO);
      invalidateDrawableCache(getResources(), darkMode);
      recreate();
    }
  }
}

代码示例来源:origin: morogoku/MTweaks-KernelAdiutorMOD

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
  // Don't initialize analytics with debug build
  if (!BuildConfig.DEBUG) {
    Fabric.with(this, new Crashlytics());
  }
  AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
  Utils.DARK_THEME = Themes.isDarkTheme(this);
  Themes.Theme theme = Themes.getTheme(this, Utils.DARK_THEME);
  if (Utils.DARK_THEME) {
    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
  } else {
    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
  }
  setTheme(theme.getStyle());
  super.onCreate(savedInstanceState);
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && setStatusBarColor()) {
    Window window = getWindow();
    window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    window.setStatusBarColor(statusBarColor());
  }
}

代码示例来源:origin: schaal/ocreader

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
  Preferences preference = Preferences.getPreference(key);
  if(preference != null) {
    switch (preference.getChangeAction()) {
      case NOTHING:
        break;
      case RECREATE:
        recreateActivity = true;
        FaviconLoader.clearCache();
        AppCompatDelegate.setDefaultNightMode(Preferences.getNightMode(sharedPreferences));
        Intent intent = getIntent();
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra(EXTRA_RECREATE_ACTIVITY, recreateActivity);
        startActivity(intent);
        finish();
        overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
        break;
      case UPDATE:
        PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean(Preferences.SYS_NEEDS_UPDATE_AFTER_SYNC.getKey(), true).apply();
        break;
    }
  }
}

代码示例来源:origin: WireGuard/wireguard-android

@Override
  public void onCreate() {
    super.onCreate();

    asyncWorker = new AsyncWorker(AsyncTask.SERIAL_EXECUTOR, new Handler(Looper.getMainLooper()));
    rootShell = new RootShell(getApplicationContext());
    toolsInstaller = new ToolsInstaller(getApplicationContext());

    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    AppCompatDelegate.setDefaultNightMode(
        sharedPreferences.getBoolean("dark_theme", false) ?
            AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO);

    tunnelManager = new TunnelManager(new FileConfigStore(getApplicationContext()));
    tunnelManager.onCreate();

    asyncWorker.supplyAsync(Application::getBackend).thenAccept(futureBackend::complete);
  }
}

代码示例来源:origin: MCMrARM/revolution-irc

public void applyThemeToActivity(Activity activity) {
  if (currentCustomThemePatcher == null && currentCustomTheme != null) {
    ThemeResourceFileBuilder.CustomTheme theme = ThemeResourceFileBuilder
        .createTheme(context, currentCustomTheme);
    currentTheme = theme;
    File themeFile = ThemeResourceFileBuilder.createThemeZipFile(context,
        theme.getResTable());
    currentCustomThemePatcher = new Theme(context, themeFile.getAbsolutePath());
  }
  if (currentCustomThemePatcher != null) {
    currentCustomThemePatcher.applyToActivity(activity);
  }
  ThemeResInfo currentBaseTheme = currentTheme;
  if (currentCustomTheme != null)
    currentBaseTheme = currentCustomTheme.baseThemeInfo;
  if (currentBaseTheme instanceof BaseTheme) {
    if (((BaseTheme) currentBaseTheme).isDark)
      AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
    else
      AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
  }
  if (mNeedsApplyIrcColors)
    IRCColorUtils.loadColors(activity.getTheme(), currentTheme.getIRCColorsResId());
}

代码示例来源:origin: schaal/ocreader

AppCompatDelegate.setDefaultNightMode(Preferences.getNightMode(preferences));

相关文章