当前位置: 首页>>代码示例>>Java>>正文


Java Context.setTheme方法代码示例

本文整理汇总了Java中android.content.Context.setTheme方法的典型用法代码示例。如果您正苦于以下问题:Java Context.setTheme方法的具体用法?Java Context.setTheme怎么用?Java Context.setTheme使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.content.Context的用法示例。


在下文中一共展示了Context.setTheme方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setTheme

import android.content.Context; //导入方法依赖的package包/类
/**
 * Called in onCreate() to check the UI Mode (day or night)
 * and set the theme colors accordingly.
 *
 * @param context {@link NavigationView} where the theme will be set
 * @param attrs   holding custom styles if any are set
 */
static void setTheme(Context context, AttributeSet attrs) {
  int uiMode = context.getResources().getConfiguration().uiMode
    & Configuration.UI_MODE_NIGHT_MASK;
  boolean darkThemeEnabled = uiMode == Configuration.UI_MODE_NIGHT_YES;
  updatePreferencesDarkEnabled(context, darkThemeEnabled);

  // Check for custom theme from NavigationLauncher
  if (shouldSetThemeFromPreferences(context)) {
    int prefLightTheme = retrieveThemeResIdFromPreferences(context, NavigationConstants.NAVIGATION_VIEW_LIGHT_THEME);
    int prefDarkTheme = retrieveThemeResIdFromPreferences(context, NavigationConstants.NAVIGATION_VIEW_DARK_THEME);
    prefLightTheme = prefLightTheme == 0 ?  R.style.NavigationViewLight : prefLightTheme;
    prefDarkTheme = prefLightTheme == 0 ?  R.style.NavigationViewDark : prefDarkTheme;
    context.setTheme(darkThemeEnabled ? prefDarkTheme : prefLightTheme);
    return;
  }

  TypedArray styledAttributes = context.obtainStyledAttributes(attrs, R.styleable.NavigationView);
  int lightTheme = styledAttributes.getResourceId(R.styleable.NavigationView_navigationLightTheme,
    R.style.NavigationViewLight);
  int darkTheme = styledAttributes.getResourceId(R.styleable.NavigationView_navigationDarkTheme,
    R.style.NavigationViewDark);
  styledAttributes.recycle();

  context.setTheme(darkThemeEnabled ? darkTheme : lightTheme);
}
 
开发者ID:mapbox,项目名称:mapbox-navigation-android,代码行数:33,代码来源:ThemeSwitcher.java

示例2: setTheme

import android.content.Context; //导入方法依赖的package包/类
public static void setTheme(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    boolean dark = prefs.getBoolean("dark_theme", false);
    String theme = prefs.getString("theme", "teal");
    if (theme.equals("teal"))
        context.setTheme(dark ? R.style.AppThemeTealDark : R.style.AppThemeTeal);
    else if (theme.equals("blue"))
        context.setTheme(dark ? R.style.AppThemeBlueDark : R.style.AppThemeBlue);
    else if (theme.equals("purple"))
        context.setTheme(dark ? R.style.AppThemePurpleDark : R.style.AppThemePurple);
    else if (theme.equals("amber"))
        context.setTheme(dark ? R.style.AppThemeAmberDark : R.style.AppThemeAmber);
    else if (theme.equals("orange"))
        context.setTheme(dark ? R.style.AppThemeOrangeDark : R.style.AppThemeOrange);
    else if (theme.equals("green"))
        context.setTheme(dark ? R.style.AppThemeGreenDark : R.style.AppThemeGreen);

    if (context instanceof Activity && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        TypedValue tv = new TypedValue();
        context.getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
        ((Activity) context).setTaskDescription(new ActivityManager.TaskDescription(null, null, tv.data));
    }
}
 
开发者ID:miankai,项目名称:MKAPP,代码行数:24,代码来源:Util.java

示例3: getThemeColor

import android.content.Context; //导入方法依赖的package包/类
/** [这个好像好用些] */
public static int getThemeColor(Context context, int themeRes, int attribute, int defaultColor) {
    int themeColor = 0;
    String packageName = context.getPackageName();
    try {
        Context packageContext = context.createPackageContext(packageName, 0);
        packageContext.setTheme(themeRes);
        Resources.Theme theme = packageContext.getTheme();
        TypedArray ta = theme.obtainStyledAttributes(new int[] {attribute});
        themeColor = ta.getColor(0, defaultColor);
        ta.recycle();
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return themeColor;
}
 
开发者ID:A-Miracle,项目名称:QiangHongBao,代码行数:17,代码来源:ResourcesUtils.java

示例4: setTheme

import android.content.Context; //导入方法依赖的package包/类
public static void setTheme(Context context) {

        SharedPreferences preferences = context.getSharedPreferences("item", MODE_PRIVATE);
        int themeId = preferences.getInt("theme", 0);

        switch (themeId) {
            case R.style.AppTheme_Red:
            case R.style.AppTheme_Pink:
            case R.style.AppTheme_Yellow:
            case R.style.AppTheme_Green:
            case R.style.AppTheme_Blue:
                context.setTheme(themeId);
                break;
            default:
                context.setTheme(R.style.AppTheme);
                break;
        }
    }
 
开发者ID:xiaofei-dev,项目名称:Vibrator,代码行数:19,代码来源:MainActivity.java

示例5: apply

import android.content.Context; //导入方法依赖的package包/类
public void apply(@NonNull Context context) {
    final boolean dark = preferences.getBoolean(KEY_THEME_DARK, false);
    // we have only 2 themes and Light one is default
    final int theme;
    if (dark) {
        theme = R.style.AppThemeBaseDark;
    } else {
        theme = R.style.AppThemeBaseLight;
    }

    final Context appContext = context.getApplicationContext();
    if (appContext != context) {
        appContext.setTheme(theme);
    }
    context.setTheme(theme);
}
 
开发者ID:noties,项目名称:Markwon,代码行数:17,代码来源:Themes.java

示例6: setDarkTheme

import android.content.Context; //导入方法依赖的package包/类
public static void setDarkTheme(Context context) {
    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
    boolean darkTheme = sharedPrefs.getBoolean(context.getString(R.string.key_themes_pref), false);
    if (darkTheme) {
        context.setTheme(R.style.AppThemeDark);
    } else {
        context.setTheme(R.style.AppThemeLight);
    }
}
 
开发者ID:personaljesusua,项目名称:DepressingThoughts,代码行数:10,代码来源:AppSettings.java

示例7: setTheme

import android.content.Context; //导入方法依赖的package包/类
/**
 * 设置当前主题
 * @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);
    }
}
 
开发者ID:wp521,项目名称:MyFire,代码行数:14,代码来源:ChangeModeController.java

示例8: showSheetDialog

import android.content.Context; //导入方法依赖的package包/类
/**
 * 显示dialog 方法
 */
public static void showSheetDialog(Context context, String cancelTitle, String[] items, boolean cancelable, MenuItemClickListener listener) {
    context.setTheme(R.style.ActionSheetStyleIOS7);
    ActionSheet menuView = new ActionSheet(context);
    menuView.setCancelButtonTitle(cancelTitle);// before add items
    menuView.addItems(items);
    menuView.setItemClickListener(listener);
    menuView.setCancelableOnTouchMenuOutside(cancelable);
    menuView.showMenu();
}
 
开发者ID:StickyTolt,项目名称:ForeverLibrary,代码行数:13,代码来源:ActionSheet.java

示例9: setTheme

import android.content.Context; //导入方法依赖的package包/类
public static void setTheme(Context context) {
    String name = getCurrentTheme(context);
    context.setTheme(getThemeByName(name, context));
}
 
开发者ID:tranleduy2000,项目名称:text_converter,代码行数:5,代码来源:ThemeHelper.java

示例10: ThemeManager

import android.content.Context; //导入方法依赖的package包/类
public ThemeManager(Context context) {
    this.context = context;

    final String prefOutput = new SharedPrefsManager(context)
            .readString(Constants.SharedPreferences.PREF_KEY_THEME);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

        if (prefOutput.equals(Constants.ThemesBright.THEME_BLUE)) {
            context.setTheme(R.style.BlueTheme);
        }
        if (prefOutput.equals(Constants.ThemesBright.THEME_PURPLE)) {
            context.setTheme(R.style.PurpleTheme);
        }
        if (prefOutput.equals(Constants.ThemesBright.THEME_GREEN)) {
            context.setTheme(R.style.GreenTheme);
        }
        if (prefOutput.equals(Constants.ThemesBright.THEME_RED_SOFT) ) {
            context.setTheme(R.style.RedsoftTheme);
        }
        if (prefOutput.equals(Constants.ThemesDark.THEME_BLUE)) {
            context.setTheme(R.style.BlueDarkTheme);
        }
        if (prefOutput.equals(Constants.ThemesDark.THEME_PURPLE)) {
            context.setTheme(R.style.PurpleDarkTheme);
        }
        if (prefOutput.equals(Constants.ThemesDark.THEME_GREEN)) {
            context.setTheme(R.style.GreenDarkTheme);
        }
        if (prefOutput.equals(Constants.ThemesDark.THEME_RED_SOFT)) {
            context.setTheme(R.style.RedsoftDarkTheme);
        }
        if (prefOutput.equals(Constants.ThemesMaterials.THEME_BLUE)|| prefOutput.equals("")) {
            context.setTheme(R.style.BlueMaterialTheme);
        }
        if (prefOutput.equals(Constants.ThemesMaterials.THEME_PURPLE)) {
            context.setTheme(R.style.PurpleMaterialTheme);
        }
        if (prefOutput.equals(Constants.ThemesMaterials.THEME_GREEN)) {
            context.setTheme(R.style.GreenMaterialTheme);
        }
        if (prefOutput.equals(Constants.ThemesMaterials.THEME_RED_SOFT)) {
            context.setTheme(R.style.RedsoftMaterialTheme);
        }
        if (prefOutput.equals("loveAndLiberty")) {
            context.setTheme(R.style.LoveAndLibertyGradientTheme);
        }
    }
}
 
开发者ID:Lidchanin,项目名称:Shopping_List,代码行数:49,代码来源:ThemeManager.java


注:本文中的android.content.Context.setTheme方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。