List of usage examples for android.util TypedValue TypedValue
TypedValue
From source file:Main.java
public static int getPrimaryColor(Context context) { TypedValue typedValue = new TypedValue(); TypedArray typedArray = context.obtainStyledAttributes(typedValue.data, new int[] { 16843827 }); int accent = typedArray.getColor(0, 0); typedArray.recycle();// ww w. j a v a 2s .com return accent; }
From source file:Main.java
public static int getTextColorPrimary(Context context) { TypedValue typedValue = new TypedValue(); TypedArray typedArray = context.obtainStyledAttributes(typedValue.data, new int[] { 16842806 }); int accent = typedArray.getColor(0, 0); typedArray.recycle();/*from ww w . ja v a2 s . c o m*/ return accent; }
From source file:Main.java
public static int getThemeColorPrimaryDark(Context ctx) { TypedValue typedValue = new TypedValue(); ctx.getTheme().resolveAttribute(android.R.attr.theme, typedValue, true); int[] attribute = new int[] { android.R.attr.colorPrimaryDark }; TypedArray array = ctx.obtainStyledAttributes(typedValue.resourceId, attribute); int color = array.getColor(0, -1); array.recycle();// ww w.jav a 2 s .c o m return color; }
From source file:Main.java
public static int getSystemUiActionBarHeight(Activity activity) { final TypedValue typedValue = new TypedValue(); if (activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, typedValue, true)) { return TypedValue.complexToDimensionPixelSize(typedValue.data, activity.getResources().getDisplayMetrics()); }// w w w . j a va 2 s .com return -1; }
From source file:Main.java
public static int getColorFromTheme(Resources.Theme theme, int color_id) { TypedValue typedValue = new TypedValue(); theme.resolveAttribute(color_id, typedValue, true); return typedValue.data; }
From source file:Main.java
static int getActionbarSize(Context context) { int actionbarSize = -1; TypedValue typedValue = new TypedValue(); if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, typedValue, true)) { actionbarSize = TypedValue.complexToDimensionPixelSize(typedValue.data, context.getResources().getDisplayMetrics()); }// w ww .j a v a 2 s. co m return actionbarSize; }
From source file:Main.java
public static int getColor(Activity activity, String attr, int fallbackColor) { TypedValue color = new TypedValue(); try {//from w w w .jav a 2 s . c om int colorId = activity.getResources().getIdentifier(attr, "attr", activity.getPackageName()); if (activity.getTheme().resolveAttribute(colorId, color, true)) { return color.data; } } catch (Exception ignored) { } return activity.getResources().getColor(fallbackColor); }
From source file:Main.java
public static int getColor(Context context, int attr) { TypedValue typedValue = new TypedValue(); Resources.Theme theme = context.getTheme(); theme.resolveAttribute(attr, typedValue, true); int color = typedValue.data; return color; }
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 {//from w w w . j a va 2 s .com return typedValue.data; } } return context.getResources().getColor(defaultResId); }
From source file:Main.java
public static int fromAttribute(Context context, int attr) { TypedValue typedValue = new TypedValue(); Resources.Theme theme = context.getTheme(); theme.resolveAttribute(attr, typedValue, true); return typedValue.data; }