List of usage examples for android.content Context getTheme
@ViewDebug.ExportedProperty(deepExport = true) public abstract Resources.Theme getTheme();
From source file:Main.java
@TargetApi(14) public static int getActionBarHeight(Context context) { int result = 0; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { TypedValue tv = new TypedValue(); context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true); result = TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics()); }/*from w w w .j av a2 s . c om*/ return result; }
From source file:com.carlrice.reader.utils.UiUtils.java
static public int getAttrResource(Context context, int attrId, int defValue) { TypedArray a = context.getTheme().obtainStyledAttributes(new int[] { attrId }); int result = a.getResourceId(0, defValue); a.recycle();/*from www . ja v a2 s. c o m*/ return result; }
From source file:Main.java
public static int getColorFromRessource(Context context, int ressourceId) { Resources res = context.getResources(); if (Build.VERSION.SDK_INT >= 23) { return res.getColor(ressourceId, context.getTheme()); } else {/*w w w. j av a2 s . c o m*/ return res.getColor(ressourceId); } }
From source file:me.henrytao.mdcore.widgets.internal.MdCheckBox.java
private static boolean hasCustomDrawable(Context context, AttributeSet attrs) { TypedArray a = context.getTheme().obtainStyledAttributes(attrs, new int[] { R.attr.srcCompat }, 0, 0); boolean result = a.getResourceId(0, 0) > 0; a.recycle();// w ww . ja v a2 s. c o m return result; }
From source file:Main.java
/** * Last but not least, try to pull the Font Path from the Theme, which is defined. * * @param context Activity Context//www .j av a 2 s.co m * @param styleId Theme style id * @param attributeId if -1 returns null. * @return null if no theme or attribute defined. */ static String pullFontPathFromTheme(Context context, int styleId, int attributeId) { if (styleId == -1 || attributeId == -1) return null; final Resources.Theme theme = context.getTheme(); final TypedValue value = new TypedValue(); theme.resolveAttribute(styleId, value, true); final TypedArray typedArray = theme.obtainStyledAttributes(value.resourceId, new int[] { attributeId }); try { return typedArray.getString(0); } catch (Exception ignore) { // Failed for some reason. return null; } finally { typedArray.recycle(); } }
From source file:com.facebook.react.views.checkbox.ReactCheckBoxManager.java
private static int getThemeColor(final Context context, String colorId) { final TypedValue value = new TypedValue(); context.getTheme().resolveAttribute(getIdentifier(context, colorId), value, true); return value.data; }
From source file:Main.java
public static Drawable getDrawable(@NonNull Context context, @DrawableRes int drawableID) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return context.getResources().getDrawable(drawableID, context.getTheme()); } else {//from w ww.j av a 2s . co m //noinspection deprecation return context.getResources().getDrawable(drawableID); } }
From source file:com.keylesspalace.tusky.util.ThemeUtils.java
public static @ColorRes int getColorId(Context context, @AttrRes int attribute) { TypedValue value = new TypedValue(); context.getTheme().resolveAttribute(attribute, value, true); return value.resourceId; }
From source file:com.reallynourl.nourl.fmpfoldermusicplayer.utility.Util.java
/** * Returns the accent color for the app set in xml. * If needed often it's more efficient to cache it locally. * @param context the current context//from w ww . j a v a2 s . c o m * @return the color as rgb */ public static int getAccentColor(final Context context) { final TypedValue value = new TypedValue(); context.getTheme().resolveAttribute(android.support.design.R.attr.colorAccent, value, true); return value.data; }
From source file:org.akop.crosswords.fragment.BaseFragment.java
public static int getThemedColor(Context context, int attrId) { Resources.Theme theme = context.getTheme(); TypedValue typedValue = new TypedValue(); theme.resolveAttribute(attrId, typedValue, true); return typedValue.data; }