Java Code Examples for android.util.TypedValue#TYPE_FIRST_COLOR_INT
The following examples show how to use
android.util.TypedValue#TYPE_FIRST_COLOR_INT .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utility.java From scene with Apache License 2.0 | 6 votes |
public static Drawable getWindowBackground(Context context) { if (context instanceof Activity) { throw new IllegalArgumentException("Use Scene Context instead"); } TypedValue a = new TypedValue(); context.getTheme().resolveAttribute(android.R.attr.windowBackground, a, true); if (a.type >= TypedValue.TYPE_FIRST_COLOR_INT && a.type <= TypedValue.TYPE_LAST_COLOR_INT) { // windowBackground is a color int color = a.data; return new ColorDrawable(color); } else { // windowBackground is not a color, probably a drawable Drawable d = context.getResources().getDrawable(a.resourceId); return d; } }
Example 2
Source File: DialogUtils.java From talk-android with MIT License | 6 votes |
public static ColorStateList resolveActionTextColorStateList(Context context, @AttrRes int colorAttr, ColorStateList fallback) { TypedArray a = context.getTheme().obtainStyledAttributes(new int[]{colorAttr}); try { final TypedValue value = a.peekValue(0); if (value == null) { return fallback; } if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT && value.type <= TypedValue.TYPE_LAST_COLOR_INT) { return getActionTextStateList(context, value.data); } else { final ColorStateList stateList = a.getColorStateList(0); if (stateList != null) { return stateList; } else { return fallback; } } } finally { a.recycle(); } }
Example 3
Source File: NavigationDrawerFragment.java From Pocket-Plays-for-Twitch with GNU General Public License v3.0 | 6 votes |
private View setOnClick(@IdRes int viewID, Class aActivity) { View view = getActivity().findViewById(viewID); if(getActivity().getClass() == aActivity) { // Get the attribute highlight color TypedValue a = new TypedValue(); getActivity().getTheme().resolveAttribute(R.attr.navigationDrawerHighlighted, a, true); if (a.type >= TypedValue.TYPE_FIRST_COLOR_INT && a.type <= TypedValue.TYPE_LAST_COLOR_INT) { int color = a.data; view.setBackgroundColor(color); } setCloseDrawerOnClick(view, mDrawerLayout, containerView); } else { setStandardOnClick(view, getActivity(), aActivity, mDrawerLayout, containerView); } return view; }
Example 4
Source File: LiveThemeComponent.java From revolution-irc with GNU General Public License v3.0 | 6 votes |
public boolean addColorAttr(StyledAttributesHelper attrs, int attr, LiveThemeManager.ColorPropertyApplier applier, ColorStateListApplier colorStateListApplier) { TypedValue typedValue = new TypedValue(); if (!attrs.getValue(attr, typedValue)) return false; if (typedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT && typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) { addColorProperty(typedValue.resourceId, applier); return true; } else if (typedValue.type != TypedValue.TYPE_NULL && colorStateListApplier != null) { try { ThemedColorStateList th = ThemedColorStateList.createFromXml( mContext.getResources(), mContext.getResources().getXml(typedValue.resourceId), getTheme()); th.attachToComponent(this, () -> colorStateListApplier.onColorStateListChanged(th.createColorStateList())); } catch (Exception e) { e.printStackTrace(); } return true; } return false; }
Example 5
Source File: StatusView.java From GracefulMovies with Apache License 2.0 | 6 votes |
public StatusView(Context context) { super(context); LayoutInflater.from(context).inflate(R.layout.layout_status_view, this, true); mLoadingIv = findViewById(R.id.status_loading_iv); mHintTv = findViewById(R.id.status_hint_tv); mReloadBtn = findViewById(R.id.status_reload_btn); mReloadBtn.setOnClickListener(v -> { if (mOnReloadListener != null) mOnReloadListener.onReconnect(); }); setClickable(true); // block other views' touch event who under this view TypedValue a = new TypedValue(); context.getTheme().resolveAttribute(android.R.attr.windowBackground, a, true); if (a.type >= TypedValue.TYPE_FIRST_COLOR_INT && a.type <= TypedValue.TYPE_LAST_COLOR_INT) { // windowBackground is a color mBgColor = a.data; setBackgroundColor(mBgColor); } else { // windowBackground is not a color, probably a drawable mBgDrawable = context.getResources().getDrawable(a.resourceId); setBackground(mBgDrawable); } }
Example 6
Source File: ThemeHelper.java From AndroidTint with Apache License 2.0 | 6 votes |
public static ColorStateList resolveActionTextColorStateList(Context context, @AttrRes int colorAttr, ColorStateList fallback) { TypedArray a = context.getTheme().obtainStyledAttributes(new int[]{colorAttr}); try { final TypedValue value = a.peekValue(0); if (value == null) { return fallback; } if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT && value.type <= TypedValue.TYPE_LAST_COLOR_INT) { return getActionTextStateList(context, value.data); } else { final ColorStateList stateList = a.getColorStateList(0); if (stateList != null) { return stateList; } else { return fallback; } } } finally { a.recycle(); } }
Example 7
Source File: CustomThemeHelper.java From Overchan-Android with GNU General Public License v3.0 | 6 votes |
public static void setCustomTheme(Context context, SparseIntArray customAttrs) { if (customAttrs == null || customAttrs.size() == 0) { currentAttrs = null; 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; }
Example 8
Source File: XmlManifestReader.java From AndroidPlugin with MIT License | 5 votes |
private static String getAttributeValue(XmlResourceParser parser, int index) { int type = parser.getAttributeValueType(index); int data = parser.getAttributeValueData(index); if (type == TypedValue.TYPE_STRING) { return parser.getAttributeValue(index); } if (type == TypedValue.TYPE_ATTRIBUTE) { return String.format("?%s%08X", getPackage(data), data); } if (type == TypedValue.TYPE_REFERENCE) { return String.format("@%s%08X", getPackage(data), data); } if (type == TypedValue.TYPE_FLOAT) { return String.valueOf(Float.intBitsToFloat(data)); } if (type == TypedValue.TYPE_INT_HEX) { return String.format("0x%08X", data); } if (type == TypedValue.TYPE_INT_BOOLEAN) { return data != 0 ? "true" : "false"; } if (type == TypedValue.TYPE_DIMENSION) { return Float.toString(complexToFloat(data)) + DIMENSION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK]; } if (type == TypedValue.TYPE_FRACTION) { return Float.toString(complexToFloat(data)) + FRACTION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK]; } if (type >= TypedValue.TYPE_FIRST_COLOR_INT && type <= TypedValue.TYPE_LAST_COLOR_INT) { return String.format("#%08X", data); } if (type >= TypedValue.TYPE_FIRST_INT && type <= TypedValue.TYPE_LAST_INT) { return String.valueOf(data); } return String.format("<0x%X, type 0x%02X>", data, type); }
Example 9
Source File: ManifestReader.java From Android-Plugin-Framework with MIT License | 5 votes |
private static String getAttributeValue(XmlResourceParser parser, int index) { int type = parser.getAttributeValueType(index); int data = parser.getAttributeValueData(index); if (type == TypedValue.TYPE_STRING) { return parser.getAttributeValue(index); } if (type == TypedValue.TYPE_ATTRIBUTE) { return String.format("?%s%08X", getPackage(data), data); } if (type == TypedValue.TYPE_REFERENCE) { return String.format("@%s%08X", getPackage(data), data); } if (type == TypedValue.TYPE_FLOAT) { return String.valueOf(Float.intBitsToFloat(data)); } if (type == TypedValue.TYPE_INT_HEX) { return String.format("0x%08X", data); } if (type == TypedValue.TYPE_INT_BOOLEAN) { return data != 0 ? "true" : "false"; } if (type == TypedValue.TYPE_DIMENSION) { return Float.toString(complexToFloat(data)) + DIMENSION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK]; } if (type == TypedValue.TYPE_FRACTION) { return Float.toString(complexToFloat(data)) + FRACTION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK]; } if (type >= TypedValue.TYPE_FIRST_COLOR_INT && type <= TypedValue.TYPE_LAST_COLOR_INT) { return String.format("#%08X", data); } if (type >= TypedValue.TYPE_FIRST_INT && type <= TypedValue.TYPE_LAST_INT) { return String.valueOf(data); } if (type == 0x07) { return String.format("@%s%08X", getPackage(data), data); } return String.format("<0x%X, type 0x%02X>", data, type); }
Example 10
Source File: Service.java From Twire with GNU General Public License v3.0 | 5 votes |
/** * Finds and returns an attribute color. If it was not found the method returns the default color */ public static int getColorAttribute(@AttrRes int attribute, @ColorRes int defaultColor, Context context) { TypedValue a = new TypedValue(); context.getTheme().resolveAttribute(attribute, a, true); if (a.type >= TypedValue.TYPE_FIRST_COLOR_INT && a.type <= TypedValue.TYPE_LAST_COLOR_INT) { return a.data; } else { return ContextCompat.getColor(context, defaultColor); } }
Example 11
Source File: ResValueFactory.java From ratel with Apache License 2.0 | 5 votes |
public ResScalarValue factory(int type, int value, String rawValue) throws AndrolibException { switch (type) { case TypedValue.TYPE_NULL: if (value == TypedValue.DATA_NULL_UNDEFINED) { // Special case $empty as explicitly defined empty value return new ResStringValue(null, value); } else if (value == TypedValue.DATA_NULL_EMPTY) { return new ResEmptyValue(value, rawValue, type); } return new ResReferenceValue(mPackage, 0, null); case TypedValue.TYPE_REFERENCE: return newReference(value, rawValue); case TypedValue.TYPE_ATTRIBUTE: return newReference(value, rawValue, true); case TypedValue.TYPE_STRING: return new ResStringValue(rawValue, value); case TypedValue.TYPE_FLOAT: return new ResFloatValue(Float.intBitsToFloat(value), value, rawValue); case TypedValue.TYPE_DIMENSION: return new ResDimenValue(value, rawValue); case TypedValue.TYPE_FRACTION: return new ResFractionValue(value, rawValue); case TypedValue.TYPE_INT_BOOLEAN: return new ResBoolValue(value != 0, value, rawValue); case TypedValue.TYPE_DYNAMIC_REFERENCE: return newReference(value, rawValue); case TypedValue.TYPE_DYNAMIC_ATTRIBUTE: return newReference(value, rawValue, true); } if (type >= TypedValue.TYPE_FIRST_COLOR_INT && type <= TypedValue.TYPE_LAST_COLOR_INT) { return new ResColorValue(value, rawValue); } if (type >= TypedValue.TYPE_FIRST_INT && type <= TypedValue.TYPE_LAST_INT) { return new ResIntValue(value, rawValue, type); } throw new AndrolibException("Invalid value type: " + type); }
Example 12
Source File: ManifestReader.java From PluginLoader with Apache License 2.0 | 5 votes |
private static String getAttributeValue(XmlResourceParser parser, int index) { int type = parser.getAttributeValueType(index); int data = parser.getAttributeValueData(index); if (type == TypedValue.TYPE_STRING) { return parser.getAttributeValue(index); } if (type == TypedValue.TYPE_ATTRIBUTE) { return String.format("?%s%08X", getPackage(data), data); } if (type == TypedValue.TYPE_REFERENCE) { return String.format("@%s%08X", getPackage(data), data); } if (type == TypedValue.TYPE_FLOAT) { return String.valueOf(Float.intBitsToFloat(data)); } if (type == TypedValue.TYPE_INT_HEX) { return String.format("0x%08X", data); } if (type == TypedValue.TYPE_INT_BOOLEAN) { return data != 0 ? "true" : "false"; } if (type == TypedValue.TYPE_DIMENSION) { return Float.toString(complexToFloat(data)) + DIMENSION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK]; } if (type == TypedValue.TYPE_FRACTION) { return Float.toString(complexToFloat(data)) + FRACTION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK]; } if (type >= TypedValue.TYPE_FIRST_COLOR_INT && type <= TypedValue.TYPE_LAST_COLOR_INT) { return String.format("#%08X", data); } if (type >= TypedValue.TYPE_FIRST_INT && type <= TypedValue.TYPE_LAST_INT) { return String.valueOf(data); } return String.format("<0x%X, type 0x%02X>", data, type); }
Example 13
Source File: AXMLPrinter.java From LibScout with Apache License 2.0 | 5 votes |
public static String getAttributeValue(AXmlResourceParser parser,int index) { int type=parser.getAttributeValueType(index); int data=parser.getAttributeValueData(index); if (type==TypedValue.TYPE_STRING) { return parser.getAttributeValue(index); } if (type==TypedValue.TYPE_ATTRIBUTE) { return String.format("?%s%08X",getPackage(data),data); } if (type==TypedValue.TYPE_REFERENCE) { return String.format("@%s%08X",getPackage(data),data); } if (type==TypedValue.TYPE_FLOAT) { return String.valueOf(Float.intBitsToFloat(data)); } if (type==TypedValue.TYPE_INT_HEX) { return String.format("0x%08X",data); } if (type==TypedValue.TYPE_INT_BOOLEAN) { return data!=0?"true":"false"; } if (type==TypedValue.TYPE_DIMENSION) { return Float.toString(complexToFloat(data))+ DIMENSION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK]; } if (type==TypedValue.TYPE_FRACTION) { return Float.toString(complexToFloat(data))+ FRACTION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK]; } if (type>=TypedValue.TYPE_FIRST_COLOR_INT && type<=TypedValue.TYPE_LAST_COLOR_INT) { return String.format("#%08X",data); } if (type>=TypedValue.TYPE_FIRST_INT && type<=TypedValue.TYPE_LAST_INT) { return String.valueOf(data); } return String.format("<0x%X, type 0x%02X>",data,type); }
Example 14
Source File: ThemeHelper.java From AndroidTint with Apache License 2.0 | 5 votes |
public static ColorStateList getActionTextColorStateList(Context context, @ColorRes int colorId) { final TypedValue value = new TypedValue(); context.getResources().getValue(colorId, value, true); if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT && value.type <= TypedValue.TYPE_LAST_COLOR_INT) { return getActionTextStateList(context, value.data); } else { if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) { //noinspection deprecation return context.getResources().getColorStateList(colorId); } else { return context.getColorStateList(colorId); } } }
Example 15
Source File: ResValueFactory.java From ArscEditor with Apache License 2.0 | 5 votes |
public ResScalarValue factory(int type, int value, String rawValue) throws IOException { switch (type) { case TypedValue.TYPE_NULL: return new ResReferenceValue(mPackage, 0, null); case TypedValue.TYPE_REFERENCE: return newReference(value, rawValue); case TypedValue.TYPE_ATTRIBUTE: return newReference(value, rawValue, true); case TypedValue.TYPE_STRING: return new ResStringValue(rawValue, value); case TypedValue.TYPE_FLOAT: return new ResFloatValue(Float.intBitsToFloat(value), value, rawValue); case TypedValue.TYPE_DIMENSION: return new ResDimenValue(value, rawValue); case TypedValue.TYPE_FRACTION: return new ResFractionValue(value, rawValue); case TypedValue.TYPE_INT_BOOLEAN: return new ResBoolValue(value != 0, value, rawValue); case 0x07: return newReference(value, rawValue); } if (type >= TypedValue.TYPE_FIRST_COLOR_INT && type <= TypedValue.TYPE_LAST_COLOR_INT) { return new ResColorValue(value, rawValue); } if (type >= TypedValue.TYPE_FIRST_INT && type <= TypedValue.TYPE_LAST_INT) { return new ResIntValue(value, rawValue, type); } throw new IOException("Invalid value type: " + type); }
Example 16
Source File: FullScreenDialogFragment.java From FullScreenDialog with Apache License 2.0 | 5 votes |
private void setThemeBackground(View view) { TypedValue a = new TypedValue(); getActivity().getTheme().resolveAttribute(android.R.attr.windowBackground, a, true); if (a.type >= TypedValue.TYPE_FIRST_COLOR_INT && a.type <= TypedValue.TYPE_LAST_COLOR_INT) { view.setBackgroundColor(a.data); } else { try { Drawable d = ResourcesCompat.getDrawable(getActivity().getResources(), a.resourceId, getActivity().getTheme()); ViewCompat.setBackground(view, d); } catch (Resources.NotFoundException ignore) { } } }
Example 17
Source File: ResourcesImpl.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@NonNull ColorStateList loadColorStateList(Resources wrapper, TypedValue value, int id, Resources.Theme theme) throws NotFoundException { if (TRACE_FOR_PRELOAD) { // Log only framework resources if ((id >>> 24) == 0x1) { final String name = getResourceName(id); if (name != null) android.util.Log.d("PreloadColorStateList", name); } } final long key = (((long) value.assetCookie) << 32) | value.data; // Handle inline color definitions. if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT && value.type <= TypedValue.TYPE_LAST_COLOR_INT) { return getColorStateListFromInt(value, key); } ComplexColor complexColor = loadComplexColorFromName(wrapper, theme, value, id); if (complexColor != null && complexColor instanceof ColorStateList) { return (ColorStateList) complexColor; } throw new NotFoundException( "Can't find ColorStateList from drawable resource ID #0x" + Integer.toHexString(id)); }
Example 18
Source File: ResourcesImpl.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Nullable ComplexColor loadComplexColor(Resources wrapper, @NonNull TypedValue value, int id, Resources.Theme theme) { if (TRACE_FOR_PRELOAD) { // Log only framework resources if ((id >>> 24) == 0x1) { final String name = getResourceName(id); if (name != null) android.util.Log.d("loadComplexColor", name); } } final long key = (((long) value.assetCookie) << 32) | value.data; // Handle inline color definitions. if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT && value.type <= TypedValue.TYPE_LAST_COLOR_INT) { return getColorStateListFromInt(value, key); } final String file = value.string.toString(); ComplexColor complexColor; if (file.endsWith(".xml")) { try { complexColor = loadComplexColorFromName(wrapper, theme, value, id); } catch (Exception e) { final NotFoundException rnf = new NotFoundException( "File " + file + " from complex color resource ID #0x" + Integer.toHexString(id)); rnf.initCause(e); throw rnf; } } else { throw new NotFoundException( "File " + file + " from drawable resource ID #0x" + Integer.toHexString(id) + ": .xml extension required"); } return complexColor; }
Example 19
Source File: ColorUtils.java From prevent with Do What The F*ck You Want To Public License | 4 votes |
private static boolean isColor(int type) { return type >= TypedValue.TYPE_FIRST_COLOR_INT && type <= TypedValue.TYPE_LAST_COLOR_INT; }
Example 20
Source File: SegmentedButtonGroup.java From SegmentedButton with Apache License 2.0 | 4 votes |
private void getAttributes(Context context, @Nullable AttributeSet attrs) { // According to docs for obtainStyledAttributes, attrs can be null and I assume that each value will be set // to the default final TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.SegmentedButtonGroup, 0, 0); // Load background if available, this can be a drawable or a color // Note: Not well documented but getDrawable will return a ColorDrawable if a color is specified if (ta.hasValue(R.styleable.SegmentedButtonGroup_android_background)) backgroundDrawable = ta.getDrawable(R.styleable.SegmentedButtonGroup_android_background); // Load background on selection if available, can be drawable or color if (ta.hasValue(R.styleable.SegmentedButtonGroup_selectedBackground)) selectedBackgroundDrawable = ta.getDrawable(R.styleable.SegmentedButtonGroup_selectedBackground); // Note: Must read radius before setBorder call in order to round the border corners! radius = ta.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_radius, 0); selectedButtonRadius = ta.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_selectedButtonRadius, 0); // Setup border for button group // Width is the thickness of the border, color is the color of the border // Dash width and gap, if the dash width is not zero will make the border dashed with a ratio between dash // width and gap borderWidth = ta.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_borderWidth, 0); borderColor = ta.getColor(R.styleable.SegmentedButtonGroup_borderColor, Color.BLACK); borderDashWidth = ta.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_borderDashWidth, 0); borderDashGap = ta.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_borderDashGap, 0); // Set the border to the read values, this will set the border values to itself but will create a // GradientDrawable containing the border setBorder(borderWidth, borderColor, borderDashWidth, borderDashGap); // Get border information for the selected button // Same defaults as the border above, however this border information will be passed to each button so that // the correct border can be rendered around the selected button selectedBorderWidth = ta.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_selectedBorderWidth, 0); selectedBorderColor = ta.getColor(R.styleable.SegmentedButtonGroup_selectedBorderColor, Color.BLACK); selectedBorderDashWidth = ta.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_selectedBorderDashWidth, 0); selectedBorderDashGap = ta.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_selectedBorderDashGap, 0); position = ta.getInt(R.styleable.SegmentedButtonGroup_position, 0); draggable = ta.getBoolean(R.styleable.SegmentedButtonGroup_draggable, false); // Update clickable property // Not updating this property sets the clickable value to false by default but this sets the default to true // while keeping the clickable value if specified in the layouot XML setClickable(ta.getBoolean(R.styleable.SegmentedButtonGroup_android_clickable, true)); ripple = ta.getBoolean(R.styleable.SegmentedButtonGroup_ripple, true); hasRippleColor = ta.hasValue(R.styleable.SegmentedButtonGroup_rippleColor); rippleColor = ta.getColor(R.styleable.SegmentedButtonGroup_rippleColor, Color.GRAY); final int dividerWidth = ta.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_dividerWidth, 1); final int dividerRadius = ta.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_dividerRadius, 0); final int dividerPadding = ta.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_dividerPadding, 0); // Load divider value if available, the divider can be either a drawable resource or a color // Load the TypedValue first and check the type to determine if color or drawable final TypedValue value = new TypedValue(); if (ta.getValue(R.styleable.SegmentedButtonGroup_divider, value)) { if (value.type == TypedValue.TYPE_REFERENCE || value.type == TypedValue.TYPE_STRING) { // Note: Odd case where Android Studio layout preview editor will fail to display a // SegmentedButtonGroup with a divider drawable because value.resourceId returns 0 and thus // ContextCompat.getDrawable will return NullPointerException // Loading drawable TypedArray.getDrawable or doing TypedArray.getResourceId fixes the problem if (isInEditMode()) { setDivider(ta.getDrawable(R.styleable.SegmentedButtonGroup_divider), dividerWidth, dividerRadius, dividerPadding); } else { setDivider(ContextCompat.getDrawable(context, value.resourceId), dividerWidth, dividerRadius, dividerPadding); } } else if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT && value.type <= TypedValue.TYPE_LAST_COLOR_INT) { // Divider is a color, value.data is the color value setDivider(value.data, dividerWidth, dividerRadius, dividerPadding); } else { // Invalid type for the divider, throw an exception throw new IllegalArgumentException("Invalid type for SegmentedButtonGroup divider in layout XML " + "resource. Must be a color or drawable"); } } int selectionAnimationInterpolator = ta.getInt(R.styleable.SegmentedButtonGroup_selectionAnimationInterpolator, ANIM_INTERPOLATOR_FAST_OUT_SLOW_IN); setSelectionAnimationInterpolator(selectionAnimationInterpolator); selectionAnimationDuration = ta.getInt(R.styleable.SegmentedButtonGroup_selectionAnimationDuration, 500); // Recycle the typed array, required once done using it ta.recycle(); }