當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。