List of usage examples for android.content Context getTheme
@ViewDebug.ExportedProperty(deepExport = true) public abstract Resources.Theme getTheme();
From source file:Main.java
public static int getABHeight(Context context) { int actionBarHeight = 0; TypedValue tva = new TypedValue(); if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tva, true)) actionBarHeight = TypedValue.complexToDimensionPixelSize(tva.data, context.getResources().getDisplayMetrics()); return actionBarHeight; }
From source file:net.yanzm.actionbarprogress.ThemeUtils.java
public static int getDisabledThemeAttrColor(@NonNull Context context, int attr) { TypedValue typedValue = new TypedValue(); context.getTheme().resolveAttribute(android.R.attr.disabledAlpha, typedValue, true); final float disabledAlpha = typedValue.getFloat(); return getThemeAttrColor(context, attr, disabledAlpha); }
From source file:Main.java
/** * Gets the action bar height in pixels/*from ww w. jav a 2 s . c o m*/ * * @param context * @return action bar height in pixels */ public static int getActionBarHeight(Context context) { TypedValue tv = new TypedValue(); View view = new View(context); if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) { return TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics()); } return 0; }
From source file:Main.java
/** * Returns an int array with the color values for the given attributes (R.attr). * Any unresolved colors will be represented by -1 *///from ww w.ja va 2 s . co m public static int[] getThemeColorIDs(final Context context, final int[] attrs) { int[] colors = new int[attrs.length]; Resources.Theme theme = context.getTheme(); for (int i = 0; i < attrs.length; i++) { TypedValue typedValue = new TypedValue(); if (theme.resolveAttribute(attrs[i], typedValue, true)) { colors[i] = typedValue.data; } else { colors[i] = -1; } } return colors; }
From source file:net.yanzm.actionbarprogress.ThemeUtils.java
public static int getThemeAttrColor(@NonNull Context context, int attr) { TypedValue typedValue = new TypedValue(); if (context.getTheme().resolveAttribute(attr, typedValue, true)) { if (typedValue.type >= TypedValue.TYPE_FIRST_INT && typedValue.type <= TypedValue.TYPE_LAST_INT) { return typedValue.data; } else if (typedValue.type == TypedValue.TYPE_STRING) { return ContextCompat.getColor(context, typedValue.resourceId); }/*from w w w .ja va 2s .c om*/ } return 0; }
From source file:Main.java
public static int resolveColor(Context context, int colorAttr, int defaultResId) { TypedValue typedValue = new TypedValue(); boolean resolved = context.getTheme().resolveAttribute(colorAttr, typedValue, true); if (resolved) { if (typedValue.type == TypedValue.TYPE_STRING) { ColorStateList stateList = context.getResources().getColorStateList(typedValue.resourceId); if (stateList != null) return stateList.getDefaultColor(); } else {// w w w .j a v a 2 s . c o m return typedValue.data; } } return context.getResources().getColor(defaultResId); }
From source file:Main.java
public static Drawable getDrawableFromRes(int res, Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) return context.getResources().getDrawable(res, context.getTheme()); else/* w w w .ja v a 2s . c o m*/ return context.getResources().getDrawable(res); }
From source file:click.kobaken.rxirohaandroid_sample.util.AndroidSupportUtil.java
public static Drawable getDrawable(Context context, @DrawableRes int drawableId) { return ResourcesCompat.getDrawable(context.getResources(), drawableId, context.getTheme()); }
From source file:Main.java
public static int getColor(Context ctx, int id) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { return ctx.getResources().getColor(id, ctx.getTheme()); } else {/*from w ww .j a v a 2 s . c o m*/ return ctx.getResources().getColor(id); } }
From source file:Main.java
private static Drawable resolveDrawable(Context context, @AttrRes int attr, @SuppressWarnings("SameParameterValue") Drawable fallback) { TypedArray a = context.getTheme().obtainStyledAttributes(new int[] { attr }); try {/*from ww w.j a v a 2 s . c om*/ Drawable d = a.getDrawable(0); if (d == null && fallback != null) d = fallback; return d; } finally { a.recycle(); } }