Java Code Examples for android.app.Activity#setTheme()

The following examples show how to use android.app.Activity#setTheme() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public void setActivity(Activity activity) {
	super.setActivity(activity);
	int resId = getBitmapRes(activity, "ssdk_oks_shake_to_share_back");
	if (resId > 0) {
		activity.setTheme(android.R.style.Theme_Dialog);
		activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
		Window win = activity.getWindow();
		win.setBackgroundDrawableResource(resId);
	}
}
 
Example 2
public static void setTheme(Activity activity) {
    final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(activity);
    activity.setTheme(THEME_LIGHT.equals(sp.getString(THEME, THEME_LIGHT)) ? R.style.light : R.style.dark);
    if (hasSmartBar()) {
        activity.getWindow().setUiOptions(ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW);
    }
}
 
Example 3
protected static void customOnCreate(Activity activity) {
    // Logger.v(activity.getLocalClassName(), "customOnCreate(), id:" +
    // activity.hashCode());
    // set main activity parameters
    if (!(activity instanceof CustomMainActivity)) {
        // Settings.setLanguage(this);
        setScreenBasic(activity);
    }

    // set screen size
    DisplayMetrics metrics = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
    Const.SCREEN_WIDTH = metrics.widthPixels;
    Const.SCREEN_HEIGHT = metrics.heightPixels;

    switch (Preferences.APPEARANCE_FONT_SIZE) {
        case PreferenceValues.VALUE_FONT_SIZE_SMALL:
            activity.setTheme(R.style.FontSizeSmall);
            break;
        case PreferenceValues.VALUE_FONT_SIZE_MEDIUM:
            activity.setTheme(R.style.FontSizeMedium);
            break;
        case PreferenceValues.VALUE_FONT_SIZE_LARGE:
            activity.setTheme(R.style.FontSizeLarge);
            break;
    }
}
 
Example 4
/**
 *
 * @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);
}
 
Example 5
/**
 * @hide 内部方法,插件框架使用
 * 插件的Activity的onCreate调用前调用此方法
 * @param activity
 * @param savedInstanceState
 */
public void handleActivityCreateBefore(Activity activity, Bundle savedInstanceState) {
    if (LOG) {
        LogDebug.d(PLUGIN_TAG, "activity create before: " + activity.getClass().getName() + " this=" + activity.hashCode() + " taskid=" + activity.getTaskId());
    }

    // 对FragmentActivity做特殊处理
    if (savedInstanceState != null) {
        //
        savedInstanceState.setClassLoader(activity.getClassLoader());
        //
        try {
            savedInstanceState.remove("android:support:fragments");
        } catch (Throwable e) {
            if (LOGR) {
                LogRelease.e(PLUGIN_TAG, "a.c.b1: " + e.getMessage(), e);
            }
        }
    }

    // 对FragmentActivity做特殊处理
    Intent intent = activity.getIntent();
    if (intent != null) {
        intent.setExtrasClassLoader(activity.getClassLoader());
        activity.setTheme(getThemeId(activity, intent));
    }
}
 
Example 6
public void setActivity(Activity activity) {
	super.setActivity(activity);
	if (dialogMode) {
		activity.setTheme(android.R.style.Theme_Dialog);
		activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
	}
	activity.getWindow().setSoftInputMode(
		       WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
 
Example 7
public void setActivity(Activity activity) {
	super.setActivity(activity);
	int resId = getBitmapRes(activity, "ssdk_oks_shake_to_share_back");
	if (resId > 0) {
		activity.setTheme(android.R.style.Theme_Dialog);
		activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
		Window win = activity.getWindow();
		win.setBackgroundDrawableResource(resId);
	}
}
 
Example 8
Source Project: Dashchan   File: ResourceUtils.java    License: Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void applyPreferredTheme(Activity activity) {
	activity.setTheme(Preferences.getThemeResource());
	if (C.API_LOLLIPOP) {
		int color = getColor(activity, android.R.attr.colorPrimary);
		activity.getWindow().setStatusBarColor(GraphicsUtils.mixColors(color, STATUS_NAVIGATION_BACKGROUND));
	}
}
 
Example 9
public void setTheme(Activity activity) {
    SharedPreferences prefs = PreferenceUtil.getDefaultSharedPreferences(activity);
    String theme = prefs.getString(PreferenceUtil.PREFERENCE_UI_THEME, PreferenceUtil.THEME_NONE);
    int themeId = getThemeId(theme, activity);
    if (themeId != 0) {
        activity.setTheme(themeId);
    }
    if (theme.equals(PreferenceUtil.THEME_BLACK)) {
        activity.getWindow().setBackgroundDrawableResource(android.R.color.black);
    }
}
 
Example 10
Source Project: guitar-tuner   File: Utils.java    License: Apache License 2.0 5 votes vote down vote up
public static void setupActivityTheme(Activity activity) {
    boolean dark = Preferences.getBoolean(activity, activity.getString(R.string.pref_dark_theme_key), false);
    if (dark) {
        activity.setTheme(R.style.AppThemeDark);
    } else {
        activity.setTheme(R.style.AppThemeLight);
    }
}
 
Example 11
Source Project: lrkFM   File: ThemedAppCompatActivity.java    License: MIT License 5 votes vote down vote up
/**
 * Reads the current theme using {@link Pref} and sets it.
 */
static void setThemeFromPreferences(Activity context) {
    String currentTheme = new Pref<String>(THEME).getValue();
    String defaultVal = context.getString(R.string.pref_themes_value_default);
    boolean defaultOrDark = currentTheme.equals(defaultVal);
    context.setTheme(defaultOrDark ? R.style.AppTheme : R.style.AppTheme_Dark);
}
 
Example 12
Source Project: androidpn-client   File: fixTheme.java    License: Apache License 2.0 5 votes vote down vote up
public static boolean fixTheme(Activity act) {
    boolean reset = false;
    TypedValue outValue = new TypedValue();
    act.getTheme().resolveAttribute(R.attr.themeName, outValue, true);
    SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(act);
    String value = mPrefs.getString("theme","dark");
    act.setTheme(getThemePref(value));
    if (!value.contentEquals(outValue.string)) {
        reset = true;
    }
    return reset;
}
 
Example 13
Source Project: Torch   File: Utils.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static void setMainTheme(Activity activity) {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            activity.setTheme(R.style.MaterialTranslucent);
        } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            activity.setTheme(R.style.HoloTranslucent);
        } else {
            activity.setTheme(R.style.HoloWithoutBar);
        }
	}
 
Example 14
Source Project: simple-view-behavior   File: BehaviorTest.java    License: MIT License 5 votes vote down vote up
@Before
public void setup() {
    Activity activity = Robolectric.setupActivity(Activity.class);
    activity.setTheme(R.style.Theme_AppCompat);
    coordinatorLayout = new CoordinatorLayout(activity);
    activity.setContentView(coordinatorLayout);
    firstView = new View(activity);
    secondView = new TestPercentageChildView(activity);

    CoordinatorLayout.LayoutParams params = new CoordinatorLayout.LayoutParams(320, 200);
    coordinatorLayout.addView(firstView, params);
    coordinatorLayout.addView(secondView, params);
}
 
Example 15
Source Project: BlackList   File: Settings.java    License: Apache License 2.0 5 votes vote down vote up
public static void applyCurrentTheme(Activity activity) {
    if (getBooleanValue(activity, Settings.UI_THEME_DARK)) {
        activity.setTheme(R.style.AppTheme_Dark);
    } else {
        activity.setTheme(R.style.AppTheme_Light);
    }
}
 
Example 16
Source Project: intra42   File: ThemeHelper.java    License: Apache License 2.0 4 votes vote down vote up
public static void setTheme(Activity activity, AppClass app) {
    applyThemeBlitheness(app);
    activity.setTheme(app.themeRes);
}
 
Example 17
Source Project: android-app   File: Themes.java    License: GNU General Public License v3.0 4 votes vote down vote up
public static void applyTheme(Activity activity, boolean actionBar) {
    activity.setTheme(actionBar ? theme.getResId() : theme.getNoActionBarResId());
    appliedThemes.put(activity, theme);
}
 
Example 18
public static void applyTheme(@NonNull final Activity activity) {

		final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);

		final AppearanceTheme theme = appearance_theme(activity, prefs);

		switch(theme) {
			case RED:
				activity.setTheme(R.style.RR_Light_Red);
				break;

			case GREEN:
				activity.setTheme(R.style.RR_Light_Green);
				break;

			case BLUE:
				activity.setTheme(R.style.RR_Light_Blue);
				break;

			case LTBLUE:
				activity.setTheme(R.style.RR_Light_LtBlue);
				break;

			case ORANGE:
				activity.setTheme(R.style.RR_Light_Orange);
				break;

			case GRAY:
				activity.setTheme(R.style.RR_Light_Gray);
				break;

			case NIGHT:
				activity.setTheme(R.style.RR_Dark);
				break;

			case NIGHT_LOWCONTRAST:
				activity.setTheme(R.style.RR_Dark_LowContrast);
				break;

			case ULTRABLACK:
				activity.setTheme(R.style.RR_Dark_UltraBlack);
				break;
		}

		applyLanguage(activity, prefs);
	}
 
Example 19
Source Project: intra42   File: ThemeHelper.java    License: Apache License 2.0 4 votes vote down vote up
public static void setTheme(Activity activity, Users user) {
    if (activity == null)
        return;

    activity.setTheme(getThemeResource(AppSettings.Theme.getEnumTheme(activity, user)));
}
 
Example 20
public void applyTheme(Activity activity) {
    activity.setTheme(getCurThemeResId());
    setSecureWindow(activity);
}