本文整理汇总了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);
}
示例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));
}
}
示例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;
}
示例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;
}
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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();
}
示例9: setTheme
import android.content.Context; //导入方法依赖的package包/类
public static void setTheme(Context context) {
String name = getCurrentTheme(context);
context.setTheme(getThemeByName(name, context));
}
示例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);
}
}
}