List of usage examples for android.content Context getTheme
@ViewDebug.ExportedProperty(deepExport = true) public abstract Resources.Theme getTheme();
From source file:com.facebook.react.views.toolbar.ReactToolbarManager.java
private static int[] getDefaultColors(Context context) { Resources.Theme theme = context.getTheme(); TypedArray toolbarStyle = null;//ww w .j a va2 s . c om TypedArray textAppearances = null; TypedArray titleTextAppearance = null; TypedArray subtitleTextAppearance = null; try { toolbarStyle = theme.obtainStyledAttributes(new int[] { getIdentifier(context, "toolbarStyle") }); int toolbarStyleResId = toolbarStyle.getResourceId(0, 0); textAppearances = theme.obtainStyledAttributes(toolbarStyleResId, new int[] { getIdentifier(context, "titleTextAppearance"), getIdentifier(context, "subtitleTextAppearance"), }); int titleTextAppearanceResId = textAppearances.getResourceId(0, 0); int subtitleTextAppearanceResId = textAppearances.getResourceId(1, 0); titleTextAppearance = theme.obtainStyledAttributes(titleTextAppearanceResId, new int[] { android.R.attr.textColor }); subtitleTextAppearance = theme.obtainStyledAttributes(subtitleTextAppearanceResId, new int[] { android.R.attr.textColor }); int titleTextColor = titleTextAppearance.getColor(0, Color.BLACK); int subtitleTextColor = subtitleTextAppearance.getColor(0, Color.BLACK); return new int[] { titleTextColor, subtitleTextColor }; } finally { recycleQuietly(toolbarStyle); recycleQuietly(textAppearances); recycleQuietly(titleTextAppearance); recycleQuietly(subtitleTextAppearance); } }
From source file:com.hellofyc.base.util.ViewUtils.java
/** * ?ActionBar//from w w w . j a v a 2s. co m */ public static int getActionBarHeight(Context context) { TypedValue tv = new TypedValue(); if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) { return TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics()); } return 0; }
From source file:org.opensilk.common.ui.util.ThemeUtils.java
public static TypedValue resolveAttr(Context context, int attr) { TypedValue outValue = new TypedValue(); context.getTheme().resolveAttribute(attr, outValue, true); return outValue; }
From source file:org.opensilk.common.ui.util.ThemeUtils.java
public static int getThemeAttrColor(Context context, int attr) { synchronized (sTypedValue) { if (context.getTheme().resolveAttribute(attr, sTypedValue, true)) { if (sTypedValue.type >= TypedValue.TYPE_FIRST_INT && sTypedValue.type <= TypedValue.TYPE_LAST_INT) { return sTypedValue.data; } else if (sTypedValue.type == TypedValue.TYPE_STRING) { return ContextCompat.getColor(context, sTypedValue.resourceId); }//from w w w.j a va2 s . com } } return 0; }
From source file:com.gudong.appkit.utils.Utils.java
/** * ?/*from w ww. j a va2s. c om*/ * * @param context * @return */ public static int getAccentColor(Context context) { TypedValue typedValue = new TypedValue(); Resources.Theme theme = context.getTheme(); theme.resolveAttribute(R.attr.theme_accent_color, typedValue, true); return typedValue.data; }
From source file:com.gudong.appkit.utils.Utils.java
/** * ??/*from w w w .ja v a2 s.co m*/ * * @return */ public static int getThemePrimaryDarkColor(Context context) { TypedValue typedValue = new TypedValue(); Resources.Theme theme = context.getTheme(); theme.resolveAttribute(R.attr.theme_color_dark, typedValue, true); return typedValue.data; }
From source file:com.gudong.appkit.utils.Utils.java
/** * ??// w ww . j a v a 2s. c o m * * @param context * @return */ public static int getThemePrimaryColor(Context context) { TypedValue typedValue = new TypedValue(); Resources.Theme theme = context.getTheme(); theme.resolveAttribute(R.attr.theme_color, typedValue, true); return typedValue.data; }
From source file:com.kaliturin.blacklist.utils.Utils.java
/** * Resolves current theme's attribute returning referenced resource id **//* w ww. jav a 2 s.c o m*/ public static int getResourceId(Context context, @AttrRes int attrRes) { return getResourceId(attrRes, context.getTheme()); }
From source file:Main.java
/** * Get a color value from a theme attribute. * @param context used for getting the color. * @param attribute theme attribute.// w w w . j a v a 2 s.c o m * @param defaultColor default to use. * @return color value */ public static int getThemeColor(Context context, int attribute, int defaultColor) { int themeColor = 0; String packageName = context.getPackageName(); try { Context packageContext = context.createPackageContext(packageName, 0); ApplicationInfo applicationInfo = context.getPackageManager().getApplicationInfo(packageName, 0); packageContext.setTheme(applicationInfo.theme); 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; }
From source file:nl.sebastiaanschool.contact.app.gui.GrabBag.java
private static Drawable loadVectorDrawable(Context context, @DrawableRes int resId) { Drawable result = vectorDrawableCache.get(resId); if (result == null) { result = VectorDrawableCompat.create(context.getResources(), resId, context.getTheme()); if (result != null) { vectorDrawableCache.put(resId, result); } else {// w ww . j av a2 s . co m vectorDrawableCache.remove(resId); } } return result; }