android.app.Activity.setTheme()方法的使用及代码示例

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

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

Activity.setTheme介绍

暂无

代码示例

代码示例来源:origin: square/leakcanary

@Override public void setTheme(int resid) {
 // We don't want this to be called with an incompatible theme.
 // This could happen if you implement runtime switching of themes
 // using ActivityLifecycleCallbacks.
 if (resid != R.style.leak_canary_LeakCanary_Base) {
  return;
 }
 super.setTheme(resid);
}

代码示例来源:origin: markzhai/AndroidPerformanceMonitor

@Override
public void setTheme(int resid) {
  // We don't want this to be called with an incompatible theme.
  // This could happen if you implement runtime switching of themes
  // using ActivityLifecycleCallbacks.
  if (resid != R.style.block_canary_BlockCanary_Base) {
    return;
  }
  super.setTheme(resid);
}

代码示例来源:origin: Tencent/tinker

private void fixActivityParams(Activity target, ActivityInfo targetAInfo) {
  target.setRequestedOrientation(targetAInfo.screenOrientation);
  target.setTheme(targetAInfo.theme);
  try {
    final Field aInfoField = ShareReflectUtil.findField(target, "mActivityInfo");
    aInfoField.set(target, targetAInfo);
  } catch (Throwable thr) {
    throw new TinkerRuntimeException("see next stacktrace.", thr);
  }
}

代码示例来源:origin: k9mail/k-9

private K9ActivityCommon(Activity activity) {
  mActivity = activity;
  setLanguage(mActivity, K9.getK9Language());
  mActivity.setTheme(getK9ThemeResourceId());
}

代码示例来源:origin: jaydenxiao2016/AndroidFire

/**
 *
 * @param ctx 上下文
 * @param style 切换style
 */
public static void changeNight(Activity ctx,int style) {
  if(mBackGroundDrawableViews == null || mOneTextColorViews == null || mBackGroundViews == null){
    throw new RuntimeException("请先调用init()初始化方法!");
  }
  ChangeModeHelper.setChangeMode(ctx, ChangeModeHelper.MODE_NIGHT);
  ctx.setTheme(style);
  showAnimation(ctx);
  refreshUI(ctx);
}

代码示例来源:origin: jaydenxiao2016/AndroidFire

/**
 *
 * @param ctx 上下文
 * @param style 切换style
 */
public static void changeDay(Activity ctx,int style) {
  if(mBackGroundDrawableViews == null || mOneTextColorViews == null || mTwoTextColorViews == null ||mThreeTextColorViews == null ||mBackGroundViews == null){
    throw new RuntimeException("请先调用init()初始化方法!");
  }
  ChangeModeHelper.setChangeMode(ctx, ChangeModeHelper.MODE_DAY);
  ctx.setTheme(style);
  showAnimation(ctx);
  refreshUI(ctx);
}

代码示例来源:origin: stackoverflow.com

protected void setActivity(Activity testActivity) {
  if (testActivity != null) {
    testActivity.setTheme(R.style.AppCompatTheme);

代码示例来源:origin: robolectric/robolectric

realActivity.setTheme(theme);

代码示例来源:origin: robolectric/robolectric

@Test
public void whenExplicitlySetOnActivity_afterSetContentView_activityGetsThemeFromActivityInManifest()
  throws Exception {
 Activity activity = activityWithAnotherThemeRule.launchActivity(null);
 activity.setTheme(R.style.Theme_Robolectric);
 Button theButton = activity.findViewById(R.id.button);
 ColorDrawable background = (ColorDrawable) theButton.getBackground();
 assertThat(background.getColor()).isEqualTo(0xffff0000);
}

代码示例来源:origin: robolectric/robolectric

@Test
public void whenExplicitlySetOnActivity_afterSetContentView_activityGetsThemeFromActivityInManifest()
  throws Exception {
 Activity activity = activityWithAnotherThemeRule.launchActivity(null);
 activity.setTheme(R.style.Theme_Robolectric);
 Button theButton = activity.findViewById(R.id.button);
 ColorDrawable background = (ColorDrawable) theButton.getBackground();
 assertThat(background.getColor()).isEqualTo(0xffff0000);
}

代码示例来源:origin: robolectric/robolectric

@Config(minSdk = M)
@Test
public void createActivity_noDisplayNotFinished_shouldThrowIllegalStateException() {
 try {
  ActivityController<Activity> controller = Robolectric.buildActivity(Activity.class);
  controller.get().setTheme(android.R.style.Theme_NoDisplay);
  controller.setup();
  // For apps targeting above Lollipop MR1, an exception "Activity <activity> did not call
  // finish() prior to onResume() completing" will be thrown
  fail("IllegalStateException should be thrown");
 } catch (IllegalStateException e) {
  // pass
 }
}

代码示例来源:origin: robolectric/robolectric

@Test
public void createActivity_noDisplayFinished_shouldFinishActivity() {
 ActivityController<Activity> controller = Robolectric.buildActivity(Activity.class);
 controller.get().setTheme(android.R.style.Theme_NoDisplay);
 controller.create();
 controller.get().finish();
 controller.start().visible().resume();
 activity = controller.get();
 assertThat(activity.isFinishing()).isTrue();
}

代码示例来源:origin: jrvansuita/MaterialAbout

public SampleHelper init() {
  activity.setTheme(theme);
  activity.findViewById(R.id.dark).setOnClickListener(this);
  activity.findViewById(R.id.light).setOnClickListener(this);
  activity.findViewById(R.id.custom).setOnClickListener(this);
  return this;
}

代码示例来源:origin: android-hacker/VirtualXposed

activity.setTheme(info.theme);

代码示例来源:origin: robolectric/robolectric

recreatedActivity.setTheme(theme);

代码示例来源:origin: TakWolf/CNode-Material-Design

public static boolean configThemeBeforeOnCreate(@NonNull Activity activity, @StyleRes int light, @StyleRes int dark) {
  boolean enable = SettingShared.isEnableThemeDark(activity);
  activity.setTheme(enable ? dark : light);
  return enable;
}

代码示例来源:origin: limpoxe/Android-Plugin-Framework

activity.setTheme(pluginAppTheme);

代码示例来源:origin: tangqi92/BuildingBlocks

public static void changeTheme(Activity activity) {
    if (!isLight) {
      activity.setTheme(R.style.Base_Theme_AppTheme_Dark);
    }
  }
}

代码示例来源:origin: AndBible/and-bible

public static void applyTheme(Activity activity) {
  ScreenSettings.isNightModeChanged();
  if (ScreenSettings.isNightMode()) {
    activity.setTheme(R.style.AppThemeNight);
  } else {
    activity.setTheme(R.style.AppThemeDay);
  }
}

代码示例来源:origin: org.robolectric/shadows-core

public boolean setThemeFromManifest() {
 ShadowApplication shadowApplication = shadowOf(realActivity.getApplication());
 AndroidManifest appManifest = shadowApplication.getAppManifest();
 if (appManifest == null) return false;
 String themeRef = appManifest.getThemeRef(realActivity.getClass().getName());
 if (themeRef != null) {
  int themeRes = realActivity.getResources().getIdentifier(themeRef.replace("@", ""), "style", appManifest.getPackageName());
  realActivity.setTheme(themeRes);
  return true;
 }
 return false;
}

相关文章

Activity类方法