public final class

AppCompatResources

extends java.lang.Object

 java.lang.Object

↳androidx.appcompat.content.res.AppCompatResources

Gradle dependencies

compile group: 'androidx.appcompat', name: 'appcompat-resources', version: '1.6.0-alpha04'

  • groupId: androidx.appcompat
  • artifactId: appcompat-resources
  • version: 1.6.0-alpha04

Artifact androidx.appcompat:appcompat-resources:1.6.0-alpha04 it located at Google repository (https://maven.google.com/)

Androidx class mapping:

androidx.appcompat.content.res.AppCompatResources android.support.v7.content.res.AppCompatResources

Overview

Class for accessing an application's resources through AppCompat, and thus any backward compatible functionality.

Summary

Methods
public static ColorStateListgetColorStateList(Context context, int resId)

Returns the from the given resource.

public static DrawablegetDrawable(Context context, int resId)

Return a drawable object associated with a particular resource ID.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Methods

public static ColorStateList getColorStateList(Context context, int resId)

Returns the from the given resource. The resource can include themeable attributes, regardless of API level.

Parameters:

context: context to inflate against
resId: the resource identifier of the ColorStateList to retrieve

public static Drawable getDrawable(Context context, int resId)

Return a drawable object associated with a particular resource ID.

This method supports inflation of , and resources on devices where platform support is not available.

Parameters:

context: context to inflate against
resId: The desired resource identifier, as generated by the aapt tool. This integer encodes the package, type, and resource entry. The value 0 is an invalid identifier.

Returns:

Drawable An object that can be used to draw this resource.

See also: ContextCompat.getDrawable(Context, int)

Source

/*
 * Copyright 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.appcompat.content.res;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.drawable.Drawable;

import androidx.annotation.ColorRes;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.ResourceManagerInternal;
import androidx.core.content.ContextCompat;

/**
 * Class for accessing an application's resources through AppCompat, and thus any backward
 * compatible functionality.
 */
@SuppressLint("RestrictedAPI") // Temporary until we have correct restriction scopes for 1.0
public final class AppCompatResources {

    private AppCompatResources() {}

    /**
     * Returns the {@link ColorStateList} from the given resource. The resource can include
     * themeable attributes, regardless of API level.
     *
     * @param context context to inflate against
     * @param resId the resource identifier of the ColorStateList to retrieve
     */
    public static ColorStateList getColorStateList(@NonNull Context context, @ColorRes int resId) {
        return ContextCompat.getColorStateList(context, resId);
    }

    /**
     * Return a drawable object associated with a particular resource ID.
     *
     * <p>This method supports inflation of {@code <vector>}, {@code <animated-vector>} and
     * {@code <animated-selector>} resources on devices where platform support is not available.</p>
     *
     * @param context context to inflate against
     * @param resId   The desired resource identifier, as generated by the aapt
     *                tool. This integer encodes the package, type, and resource
     *                entry. The value 0 is an invalid identifier.
     * @return Drawable An object that can be used to draw this resource.
     * @see ContextCompat#getDrawable(Context, int)
     */
    @Nullable
    public static Drawable getDrawable(@NonNull Context context, @DrawableRes int resId) {
        return ResourceManagerInternal.get().getDrawable(context, resId);
    }
}