android.support.v7.app.AppCompatDelegate.setLocalNightMode()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(80)

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

AppCompatDelegate.setLocalNightMode介绍

暂无

代码示例

代码示例来源:origin: kaku2015/ColorfulNews

public void changeToDay() {
//        AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
    getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
    mNightView.setBackgroundResource(android.R.color.transparent);
  }

代码示例来源:origin: kaku2015/ColorfulNews

public void changeToNight() {
//        AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
    getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
    initNightView();
    mNightView.setBackgroundResource(R.color.night_mask);
  }

代码示例来源:origin: a-voyager/WeekToDo

public void switchNightMode(boolean toNight, boolean auto) {
  if (auto) {
    getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_AUTO);
    return;
  }
  if (toNight)
    getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
  else
    getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}

代码示例来源:origin: a-voyager/WeekToDo

@Override
public void onAnimationEnd(Animator animation) {
  animation.removeAllListeners();
  if (auto) {
    getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_AUTO);
    return;
  }
  if (toNight)
    getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
  else
    getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}

代码示例来源:origin: captain-miao/OptionRoundCardview

@Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case R.id.action_night_mode: {
        sIsNight = !sIsNight;
        if(sIsNight) {
          getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
        } else {
          getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
        }
        mMenuItem.setChecked(sIsNight);
        return true;
      }
    }
    return super.onOptionsItemSelected(item);
  }
}

代码示例来源:origin: kebernet/shortyz

@Override
public void restoreNightMode(ShortyzActivity shortyzActivity) {
  if(shortyzActivity.nightMode.isNightMode()){
    shortyzActivity.getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
  } else {
    shortyzActivity.getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
  }
}

代码示例来源:origin: gigabytedevelopers/FireFiles

public static void changeThemeStyle(AppCompatDelegate delegate) {
  int nightMode = Integer.valueOf(SettingsActivity.getThemeStyle());
  AppCompatDelegate.setDefaultNightMode(nightMode);
  delegate.setLocalNightMode(nightMode);
}

代码示例来源:origin: hymanme/MaterialHome

@Override
  public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    SPUtils.setPrefBoolean(Constant.THEME_MODEL, isChecked);
    mThemeSwitch.setChecked(isChecked);
    if (isChecked) {
      getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
    } else {
      getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
    }
  }
});

代码示例来源:origin: kebernet/shortyz

@Override
public void toggleNightMode(ShortyzActivity activity){
  activity.nightMode.toggle();
  if(activity.nightMode.isNightMode()){
    activity.getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
  } else {
    activity.getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
  }
}

代码示例来源:origin: ymback/NGA-CLIENT-VER-OPEN-SOURCE

@Override
protected void updateThemeUi() {
  setTheme(mThemeManager.getTheme(false));
  if (mThemeManager.isNightMode()) {
    getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
  } else {
    getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
  }
}

代码示例来源:origin: tianzhijiexian/EasyDialog

@Override
protected void onCreate(Bundle savedInstanceState) {
  getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
  
  super.onCreate(savedInstanceState);
  findViewById(R.id.dayNight_btn).setOnClickListener(
      v -> startActivity(new Intent(this, MainActivity.class)));
}

代码示例来源:origin: leelit/STUer-client

public static boolean isNightMode(AppCompatActivity activity) {
    int uiMode = activity.getResources().getConfiguration().uiMode;
    int dayNightUiMode = uiMode & Configuration.UI_MODE_NIGHT_MASK;
    if (SPUtils.getBoolean(MainActivity.CURRENT_NIGHT_MODE) && dayNightUiMode != Configuration.UI_MODE_NIGHT_YES) {
      activity.getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
      activity.recreate();
      return true;
    }
    return false;
  }
}

代码示例来源:origin: ricknout/lens-launcher

protected void updateNightMode() {
    if (mSettings == null) {
      mSettings = new Settings(this);
    }
    getDelegate().setLocalNightMode(mSettings.getNightMode());
  }
}

代码示例来源:origin: ymback/NGA-CLIENT-VER-OPEN-SOURCE

protected void updateThemeUi() {
  ThemeManager tm = ThemeManager.getInstance();
  setTheme(tm.getTheme(mActionBarEnabled));
  if (tm.isNightMode()) {
    getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
  } else {
    getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
  }
}

代码示例来源:origin: hymanme/MaterialHome

private void initNavView() {
  boolean night = SPUtils.getPrefBoolean(Constant.THEME_MODEL, false);
  if (night) {
    getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
  } else {
    getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
  }
  MenuItem item = mNavigationView.getMenu().findItem(R.id.nav_theme);
  mNavigationView.getMenu().findItem(R.id.nav_home).setChecked(true);
  mThemeSwitch = (SwitchCompat) MenuItemCompat.getActionView(item).findViewById(R.id.view_switch);
  mThemeSwitch.setChecked(night);
  mThemeSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
      SPUtils.setPrefBoolean(Constant.THEME_MODEL, isChecked);
      mThemeSwitch.setChecked(isChecked);
      if (isChecked) {
        getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
      } else {
        getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
      }
    }
  });
}

代码示例来源:origin: WangDaYeeeeee/GeometricWeather

@SuppressLint("RestrictedApi")
private void setDarkMode(boolean dayTime) {
  if (GeometricWeather.getInstance().getDarkMode().equals("auto")) {
    boolean isDarkMode = DisplayUtils.isDarkMode(this);
    if ((isDarkMode && dayTime) || (!isDarkMode && !dayTime)) {
      // need switch theme.
      int mode = dayTime ? AppCompatDelegate.MODE_NIGHT_NO : AppCompatDelegate.MODE_NIGHT_YES;
      getDelegate().setLocalNightMode(mode);
      AppCompatDelegate.setDefaultNightMode(mode);
      int rootColor = ContextCompat.getColor(this, R.color.colorRoot);
      refreshLayout.setProgressBackgroundColorSchemeColor(rootColor);
      indicator.setCurrentIndicatorColor(ContextCompat.getColor(this, R.color.colorAccent));
      indicator.setIndicatorColor(ContextCompat.getColor(this, R.color.colorTextSubtitle));
      refreshBackgroundViews();
    }
  }
}

代码示例来源:origin: WhiteDG/BihuDaily

@Override
public boolean onOptionsItemSelected(MenuItem item) {
  switch (item.getItemId()) {
    case android.R.id.home:
      // Open the navigation drawer when the home icon is selected from the toolbar.
      mDrawerLayout.openDrawer(GravityCompat.START);
      return true;
    case R.id.action_setting:
      ActivityUtils.toSettingActivity(this);
      break;
    case R.id.action_night:
      int uiMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
      switch (uiMode) {
        case Configuration.UI_MODE_NIGHT_NO://当前日间模式
          SPUtils.put(DailyActivity.this, Constant.KEY_NIGHT, true);
          getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
          break;
        case Configuration.UI_MODE_NIGHT_YES://当前夜间模式
          SPUtils.put(DailyActivity.this, Constant.KEY_NIGHT, false);
          getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
          break;
      }
      getSupportFragmentManager().getFragments().clear();
      recreate();
      return true;
  }
  return super.onOptionsItemSelected(item);
}

代码示例来源:origin: whyalwaysmea/BigBoom

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_search_movie_list);
  SPUtils spUtils = new SPUtils(this, Constants.SP.SHARED_PREFERENCES_NAME);
  if(spUtils.getBoolean(Constants.SP.THEME)) {
    getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
    StatusBarUtil.setColor(this, getResources().getColor(R.color.primary_night), 0);
  } else {
    StatusBarUtil.setColor(this, getResources().getColor(R.color.colorPrimary), 0);
  }
  ButterKnife.bind(this);
  init();
}

代码示例来源:origin: geminiwen/SkinSprite

public void setDayNightMode(@AppCompatDelegate.NightMode int nightMode) {
  final boolean isPost21 = Build.VERSION.SDK_INT >= 21;
  if (mSkinnableCallback != null) {
    mSkinnableCallback.beforeApplyDayNight();
  }
  getDelegate().setLocalNightMode(nightMode);
  if (isPost21) {
    applyDayNightForStatusBar();
    applyDayNightForActionBar();
  }
  View decorView = getWindow().getDecorView();
  applyDayNightForView(decorView);
  if (mSkinnableCallback != null) {
    mSkinnableCallback.onApplyDayNight();
  }
}

代码示例来源:origin: dotWee/MicroPinner

private static void changeUiMode(@NonNull ActivityTestRule<MainDialog> activityTestRule, int mode) {
  activityTestRule.getActivity().runOnUiThread(() -> activityTestRule.getActivity().getDelegate().setLocalNightMode(mode));
  // recreate activity to apply theme
  recreateActivity(activityTestRule);
}

相关文章

微信公众号

最新文章

更多