List of usage examples for android.content Context getTheme
@ViewDebug.ExportedProperty(deepExport = true) public abstract Resources.Theme getTheme();
From source file:android.support.v7.content.res.AppCompatResources.java
/** * Inflates a {@link ColorStateList} from resources, honouring theme attributes. *///ww w . j a va 2s. com @Nullable private static ColorStateList inflateColorStateList(Context context, int resId) { if (isColorInt(context, resId)) { // The resource is a color int, we can't handle it so return null return null; } final Resources r = context.getResources(); final XmlPullParser xml = r.getXml(resId); try { return AppCompatColorStateListInflater.createFromXml(r, xml, context.getTheme()); } catch (Exception e) { Log.e(LOG_TAG, "Failed to inflate ColorStateList, leaving it to the framework", e); } return null; }
From source file:android.support.v7.app.MediaRouterThemeHelper.java
private static int getThemeColor(Context context, int style, int attr) { if (style != 0) { int[] attrs = { attr }; TypedArray ta = context.obtainStyledAttributes(style, attrs); int color = ta.getColor(0, 0); ta.recycle();/*from w w w. ja va 2s . c om*/ if (color != 0) { return color; } } TypedValue value = new TypedValue(); context.getTheme().resolveAttribute(attr, value, true); if (value.resourceId != 0) { return context.getResources().getColor(value.resourceId); } return value.data; }
From source file:com.nttec.everychan.ui.theme.CustomThemeHelper.java
public static void setCustomTheme(Context context, SparseIntArray customAttrs) { if (customAttrs == null || customAttrs.size() == 0) { currentAttrs = null;//w w w.j a v a 2s .com return; } TypedValue tmp = new TypedValue(); context.getTheme().resolveAttribute(android.R.attr.textColorPrimary, tmp, true); int textColorPrimaryOriginal = (tmp.type >= TypedValue.TYPE_FIRST_COLOR_INT && tmp.type <= TypedValue.TYPE_LAST_COLOR_INT) ? tmp.data : Color.TRANSPARENT; int textColorPrimaryOverridden = customAttrs.get(android.R.attr.textColorPrimary, textColorPrimaryOriginal); try { processWindow(context, customAttrs, textColorPrimaryOriginal, textColorPrimaryOverridden); } catch (Exception e) { Logger.e(TAG, e); } CustomThemeHelper instance = new CustomThemeHelper(context, customAttrs, textColorPrimaryOriginal, textColorPrimaryOverridden); LayoutInflaterCompat.setFactory(instance.inflater, instance); currentAttrs = customAttrs; }
From source file:im.vector.util.ThemeUtils.java
/** * Translates color attributes to colors * * @param c Context/*w w w . jav a2 s . com*/ * @param colorAttribute Color Attribute * @return Requested Color */ public static @ColorInt int getColor(Context c, @AttrRes final int colorAttribute) { if (mColorByAttr.containsKey(colorAttribute)) { return mColorByAttr.get(colorAttribute); } int matchedColor; try { TypedValue color = new TypedValue(); c.getTheme().resolveAttribute(colorAttribute, color, true); matchedColor = color.data; } catch (Exception e) { matchedColor = ContextCompat.getColor(c, android.R.color.holo_red_dark); } mColorByAttr.put(colorAttribute, matchedColor); return matchedColor; }
From source file:com.silentcircle.common.util.ViewUtil.java
public static int getColorIdFromAttributeId(final Context context, final int attributeId) { TypedValue typedValue = new TypedValue(); context.getTheme().resolveAttribute(attributeId, typedValue, true); return typedValue.resourceId; }
From source file:com.silentcircle.common.util.ViewUtil.java
public static void tintMenuIcons(@NonNull Context context, @NonNull Menu menu) { TypedValue typedValue = new TypedValue(); context.getTheme().resolveAttribute(R.attr.sp_actionbar_title_text_color, typedValue, true); int color = ContextCompat.getColor(context, typedValue.resourceId); tintMenuIcons(menu, color);/*w w w. j ava 2 s.c o m*/ }
From source file:ticwear.design.app.DatetimePickerDialog.java
@StyleRes static int resolveDialogTheme(Context context, @StyleRes int resId) { if (resId == 0) { final TypedValue outValue = new TypedValue(); context.getTheme().resolveAttribute(android.R.attr.datePickerDialogTheme, outValue, true); return outValue.resourceId; } else {//from w w w .j a v a2s. c om return resId; } }
From source file:io.github.hidroh.materialistic.AppUtils.java
public static int getThemedResId(Context context, @AttrRes int attr) { TypedArray a = context.getTheme().obtainStyledAttributes(new int[] { attr }); final int resId = a.getResourceId(0, 0); a.recycle();/*w w w . ja va 2 s. c o m*/ return resId; }
From source file:com.finchuk.clock2.timepickers.Utils.java
public static int getTextColorFromThemeAttr(Context context, int resid) { // http://stackoverflow.com/a/33839580/5055032 // final TypedValue value = new TypedValue(); // context.getTheme().resolveAttribute(resid, value, true); // TypedArray a = context.obtainStyledAttributes(value.data, // new int[] {resid}); TypedArray a = context.getTheme().obtainStyledAttributes(new int[] { resid }); final int color = a.getColor(0/*index*/, 0/*defValue*/); a.recycle();/* w w w.j ava 2s . com*/ return color; // Didn't work! Gave me white! // return getColorFromThemeAttr(context, android.R.attr.textColorPrimary); }
From source file:android.support.v7.internal.widget.ThemeUtils.java
static int getDisabledThemeAttrColor(Context context, int attr) { final ColorStateList csl = getThemeAttrColorStateList(context, attr); if (csl != null && csl.isStateful()) { // If the CSL is stateful, we'll assume it has a disabled state and use it return csl.getColorForState(DISABLED_STATE_SET, csl.getDefaultColor()); } else {/*from w ww. j a va2s . c o m*/ // Else, we'll generate the color using disabledAlpha from the theme final TypedValue tv = getTypedValue(); // Now retrieve the disabledAlpha value from the theme context.getTheme().resolveAttribute(android.R.attr.disabledAlpha, tv, true); final float disabledAlpha = tv.getFloat(); return getThemeAttrColor(context, attr, disabledAlpha); } }