android.content.Context.setTheme()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(302)

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

Context.setTheme介绍

暂无

代码示例

代码示例来源:origin: oasisfeng/condom

@Override public void setTheme(int resid) {
  mBase.setTheme(resid);
}

代码示例来源:origin: TeamNewPipe/NewPipe

/**
 * Apply the selected theme (on NewPipe settings) in the context,
 * themed according with the styles defined for the service .
 *
 * @param context   context that the theme will be applied
 * @param serviceId the theme will be styled to the service with this id,
 *                  pass -1 to get the default style
 */
public static void setTheme(Context context, int serviceId) {
  context.setTheme(getThemeForService(context, serviceId));
}

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

/**
 * 设置当前主题
 * @param ctx  上下文
 * @param Style_Day  白天
 * @param Style_Night 夜间
 */
public static void setTheme(Context ctx,int Style_Day,int Style_Night){
  if(ChangeModeHelper.getChangeMode(ctx) == ChangeModeHelper.MODE_DAY){
    ctx.setTheme(Style_Day);
  }else if(ChangeModeHelper.getChangeMode(ctx) == ChangeModeHelper.MODE_NIGHT){
    ctx.setTheme(Style_Night);
  }
}

代码示例来源:origin: ankidroid/Anki-Android

public static void setThemeLegacy(Context context) {
  SharedPreferences prefs = AnkiDroidApp.getSharedPrefs(context.getApplicationContext());
  if (prefs.getBoolean("invertedColors", false)) {
    int theme = Integer.parseInt(prefs.getString("nightTheme", "0"));
    switch (theme) {
      case THEME_NIGHT_DARK:
        context.setTheme(R.style.LegacyActionBarDark);
        break;
      case THEME_NIGHT_BLACK:
        context.setTheme(R.style.LegacyActionBarBlack);
        break;
    }
  } else {
    int theme = Integer.parseInt(prefs.getString("dayTheme", "0"));
    switch (theme) {
      case THEME_DAY_LIGHT:
        context.setTheme(R.style.LegacyActionBarLight);
        break;
      case THEME_DAY_PLAIN:
        context.setTheme(R.style.LegacyActionBarPlain);
        break;
    }
  }
}

代码示例来源:origin: ankidroid/Anki-Android

public static void setTheme(Context context) {
  SharedPreferences prefs = AnkiDroidApp.getSharedPrefs(context.getApplicationContext());
  if (prefs.getBoolean("invertedColors", false)) {
    int theme = Integer.parseInt(prefs.getString("nightTheme", "0"));
    switch (theme) {
      case THEME_NIGHT_DARK:
        context.setTheme(R.style.Theme_Dark_Compat);
        break;
      case THEME_NIGHT_BLACK:
        context.setTheme(R.style.Theme_Black_Compat);
        break;
    }
  } else {
    int theme = Integer.parseInt(prefs.getString("dayTheme", "0"));
    switch (theme) {
      case THEME_DAY_LIGHT:
        context.setTheme(R.style.Theme_Light_Compat);
        break;
      case THEME_DAY_PLAIN:
        context.setTheme(R.style.Theme_Plain_Compat);
        break;
    }
  }
}

代码示例来源:origin: hidroh/materialistic

public static void apply(Context context, boolean dialogTheme, boolean isTranslucent) {
  ThemePreference.ThemeSpec themeSpec = getTheme(context, isTranslucent);
  context.setTheme(themeSpec.theme);
  if (themeSpec.themeOverrides >= 0) {
    context.getTheme().applyStyle(themeSpec.themeOverrides, true);
  }
  if (dialogTheme) {
    context.setTheme(AppUtils.getThemedResId(context, R.attr.alertDialogTheme));
  }
}

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

@Test
public void shouldFindInheritedAndroidAttributeInTheme() throws Exception {
 context.setTheme(R.style.Theme_AnotherTheme);
 Resources.Theme theme1 = context.getTheme();
 TypedArray typedArray =
   theme1.obtainStyledAttributes(new int[] {R.attr.typeface, android.R.attr.buttonStyle});
 assertThat(typedArray.hasValue(0)).isTrue(); // animalStyle
 assertThat(typedArray.hasValue(1)).isTrue(); // layout_height
}

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

/**
 * Used by plugin for Theme
 * 插件使用插件主题
 */
public static void setTheme(Context pluginContext, int resId) {
  if (pluginContext instanceof PluginContextTheme) {
    ((PluginContextTheme)pluginContext).mTheme = null;
    pluginContext.setTheme(resId);
  }
}

代码示例来源:origin: Trumeet/MiPushFramework

@Override public void setTheme(int resid) {
  mBase.setTheme(resid);
}

代码示例来源:origin: facebook/litho

mComponentContext.getAndroidContext().setTheme(0);

代码示例来源:origin: cSploit/android

SharedPreferences themePrefs = getActivity().getBaseContext().getSharedPreferences("THEME", 0);
if (themePrefs.getBoolean("isDark", false))
  getContext().setTheme(R.style.PrefsThemeDark);
else
  getActivity().setTheme(R.style.PrefsTheme);

代码示例来源:origin: GeekGhost/Ghost

context.setTheme(R.style.BlueTheme);
  PreUtils.setCurrentTheme(context, Theme.Blue);
  PreUtils.putString(context, Constants.PRIMARYCOLOR, "#2196F3");
  PreUtils.putString(context, Constants.TITLECOLOR, "#ffffff");
} else if (selectedColor == context.getResources().getColor(R.color.colorRedPrimary)) {
  context.setTheme(R.style.RedTheme);
  PreUtils.setCurrentTheme(context, Theme.Red);
  PreUtils.putString(context, Constants.PRIMARYCOLOR, "#F44336");
  PreUtils.putString(context, Constants.TITLECOLOR, "#ffffff");
} else if (selectedColor == context.getResources().getColor(R.color.colorBrownPrimary)) {
  context.setTheme(R.style.BrownTheme);
  PreUtils.setCurrentTheme(context, Theme.Brown);
  PreUtils.putString(context, Constants.PRIMARYCOLOR, "#795548");
  PreUtils.putString(context, Constants.TITLECOLOR, "#ffffff");
} else if (selectedColor == context.getResources().getColor(R.color.colorGreenPrimary)) {
  context.setTheme(R.style.GreenTheme);
  PreUtils.setCurrentTheme(context, Theme.Green);
  PreUtils.putString(context, Constants.PRIMARYCOLOR, "#4CAF50");
  PreUtils.putString(context, Constants.TITLECOLOR, "#ffffff");
} else if (selectedColor == context.getResources().getColor(R.color.colorPurplePrimary)) {
  context.setTheme(R.style.PurpleTheme);
  PreUtils.setCurrentTheme(context, Theme.Purple);
  PreUtils.putString(context, Constants.PRIMARYCOLOR, "#9c27b0");
  PreUtils.putString(context, Constants.TITLECOLOR, "#ffffff");
} else if (selectedColor == context.getResources().getColor(R.color.colorTealPrimary)) {
  context.setTheme(R.style.TealTheme);
  PreUtils.setCurrentTheme(context, Theme.Teal);
  PreUtils.putString(context, Constants.PRIMARYCOLOR, "#009688");
  PreUtils.putString(context, Constants.TITLECOLOR, "#ffffff");

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

pluginContext.setTheme(pluginAppTheme);

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

public class Application extends android.app.Application {
  public static Context AppContext = null;

  @Override
  public void onCreate() {
    super.onCreate();
    AppContext = getApplicationContext();

    // You can use this line to solve styling problems
    // because Manifest android:theme is not working
    AppContext.setTheme(R.style.AppTheme);
  }
}

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

Context context = getInstrumentation().getTargetContext();
context.setTheme(R.style.Theme_AppCompat);
mActivity = launchActivity(context.getPackageName(),
  MyActivity.class, null);
getInstrumentation().waitForIdleSync();

// YOUR TESTS
// assertNotNull("The activity cannot be null.", mActivity);

sendKeys(KeyEvent.KEYCODE_BACK);
mActivity.finish();

代码示例来源:origin: oliexdev/openScale

public static void applyTheme(Context context) {
  SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
  if (prefs.getString(PREFERENCE_APP_THEME, "").equals("Dark")) {
    context.setTheme(R.style.AppTheme_Dark);
  }
}

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

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
  //get the parent activity context and set it's theme again.
  Context ctx = getActivity();
  ctx.setTheme(android.R.style.Theme_Holo_Light);
  AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
  LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  View view = inflater.inflate(R.layout.your_dialog_layout, null, false);
  builder.setView(view);

  //your other code for the dialog
  //

  return builder.create();

代码示例来源:origin: vanilla-music/vanilla

/**
 * Calls context.setTheme() with given theme.
 * Will automatically swap the theme with an alternative
 * version if the user requested us to use it
 */
final public static void setTheme(Context context, int theme) {
  context.setTheme(getThemeResource(context, theme));
}

代码示例来源:origin: xiaoxiangyeyuHeaven/HeavenlyModule

/**
 * 设置当前主题
 * @param ctx  上下文
 * @param Style_Day  白天
 * @param Style_Night 夜间
 */
public static void setTheme(Context ctx, int Style_Day, int Style_Night){
  if(ChangeModeHelper.getChangeMode(ctx) == ChangeModeHelper.MODE_DAY){
    ctx.setTheme(Style_Day);
  }else if(ChangeModeHelper.getChangeMode(ctx) == ChangeModeHelper.MODE_NIGHT){
    ctx.setTheme(Style_Night);
  }
}

代码示例来源:origin: plusonelabs/calendar-widget

public void onDataSetChanged() {
  context.setTheme(themeNameToResId(getSettings().getEntryTheme()));
  if (getSettings().getShowDayHeaders())
    mWidgetEntries = addDayHeaders(getEventEntries());
  else
    mWidgetEntries = getEventEntries();
}

相关文章

Context类方法