Java Code Examples for androidx.appcompat.widget.TintTypedArray#getResourceId()
The following examples show how to use
androidx.appcompat.widget.TintTypedArray#getResourceId() .
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: MaterialResources.java From material-components-android with Apache License 2.0 | 6 votes |
/** * Returns the {@link ColorStateList} from the given {@link TintTypedArray} attributes. The * resource can include themeable attributes, regardless of API level. */ @Nullable public static ColorStateList getColorStateList( @NonNull Context context, @NonNull TintTypedArray attributes, @StyleableRes int index) { if (attributes.hasValue(index)) { int resourceId = attributes.getResourceId(index, 0); if (resourceId != 0) { ColorStateList value = AppCompatResources.getColorStateList(context, resourceId); if (value != null) { return value; } } } // Reading a single color with getColorStateList() on API 15 and below doesn't always correctly // read the value. Instead we'll first try to read the color directly here. if (VERSION.SDK_INT <= VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { int color = attributes.getColor(index, -1); if (color != -1) { return ColorStateList.valueOf(color); } } return attributes.getColorStateList(index); }
Example 2
Source File: NavigationView.java From material-components-android with Apache License 2.0 | 6 votes |
/** * Creates a {@link MaterialShapeDrawable} to use as the {@code itemBackground} and wraps it in an * {@link InsetDrawable} for margins. * * @param a The TintTypedArray containing the resolved NavigationView style attributes. */ @NonNull private final Drawable createDefaultItemBackground(@NonNull TintTypedArray a) { int shapeAppearanceResId = a.getResourceId(R.styleable.NavigationView_itemShapeAppearance, 0); int shapeAppearanceOverlayResId = a.getResourceId(R.styleable.NavigationView_itemShapeAppearanceOverlay, 0); MaterialShapeDrawable materialShapeDrawable = new MaterialShapeDrawable( ShapeAppearanceModel.builder( getContext(), shapeAppearanceResId, shapeAppearanceOverlayResId) .build()); materialShapeDrawable.setFillColor( MaterialResources.getColorStateList( getContext(), a, R.styleable.NavigationView_itemShapeFillColor)); int insetLeft = a.getDimensionPixelSize(R.styleable.NavigationView_itemShapeInsetStart, 0); int insetTop = a.getDimensionPixelSize(R.styleable.NavigationView_itemShapeInsetTop, 0); int insetRight = a.getDimensionPixelSize(R.styleable.NavigationView_itemShapeInsetEnd, 0); int insetBottom = a.getDimensionPixelSize(R.styleable.NavigationView_itemShapeInsetBottom, 0); return new InsetDrawable(materialShapeDrawable, insetLeft, insetTop, insetRight, insetBottom); }
Example 3
Source File: TabItem.java From material-components-android with Apache License 2.0 | 5 votes |
public TabItem(Context context, AttributeSet attrs) { super(context, attrs); final TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.TabItem); text = a.getText(R.styleable.TabItem_android_text); icon = a.getDrawable(R.styleable.TabItem_android_icon); customLayout = a.getResourceId(R.styleable.TabItem_android_layout, 0); a.recycle(); }