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

The following examples show how to use android.app.Activity#setTheme() . 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
Source File: ResourceUtils.java    From Dashchan with 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 2
Source File: Settings.java    From BlackList with 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 3
Source File: BehaviorTest.java    From simple-view-behavior with 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 4
Source File: Utils.java    From Torch with 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 5
Source File: fixTheme.java    From androidpn-client with 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 6
Source File: ThemedAppCompatActivity.java    From lrkFM with 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 7
Source File: Utils.java    From guitar-tuner with 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 8
Source File: ThemeManagerAbstract.java    From YalpStore with GNU General Public License v2.0 5 votes vote down vote up
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 9
Source File: Shake2Share.java    From AndroidLinkup with GNU General Public License v2.0 5 votes vote down vote up
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 10
Source File: Shake2Share.java    From ShareSDKShareDifMsgDemo-Android with MIT License 5 votes vote down vote up
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 11
Source File: EditPage.java    From -Android_ShareSDK_Example_Wechat with MIT License 5 votes vote down vote up
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 12
Source File: PluginLibraryInternalProxy.java    From springreplugin with Apache License 2.0 5 votes vote down vote up
/**
 * @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 13
Source File: ChangeModeController.java    From youqu_master with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @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 14
Source File: CustomActivity.java    From WhereYouGo with GNU General Public License v3.0 5 votes vote down vote up
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 15
Source File: ThemeUtils.java    From prevent with Do What The F*ck You Want To Public License 5 votes vote down vote up
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 16
Source File: PrefsUtility.java    From RedReader with GNU General Public License v3.0 4 votes vote down vote up
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 17
Source File: ThemeHelper.java    From intra42 with 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 18
Source File: FDroidApp.java    From fdroidclient with GNU General Public License v3.0 4 votes vote down vote up
public void applyTheme(Activity activity) {
    activity.setTheme(getCurThemeResId());
    setSecureWindow(activity);
}
 
Example 19
Source File: Themes.java    From android-app with 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 20
Source File: ThemeHelper.java    From intra42 with Apache License 2.0 4 votes vote down vote up
public static void setTheme(Activity activity, AppClass app) {
    applyThemeBlitheness(app);
    activity.setTheme(app.themeRes);
}