Most visited

Recently visited

DrawableCompat

public final class DrawableCompat
extends Object

java.lang.Object
    android.support.v4.graphics.drawable.DrawableCompat


Helper用于访问在向后兼容的API级别4之后引入的 Drawable功能。

摘要(Summary)

公共方法(Public methods)

static void applyTheme(Drawable drawable, Resources.Theme t)

将指定的主题应用于此Drawable及其子项。

static boolean canApplyTheme(Drawable drawable)

一个主题是否可以应用于这个Drawable及其子节点。

static int getAlpha(Drawable drawable)

获取 drawable的Alpha值。

static ColorFilter getColorFilter(Drawable drawable)

返回当前的颜色过滤器,如果没有设置,则返回 null

static int getLayoutDirection(Drawable drawable)

返回此Drawable的已解析布局方向。

static void inflate(Drawable drawable, Resources res, XmlPullParser parser, AttributeSet attrs, Resources.Theme theme)

从可选的由主题设计的XML资源中扩展此Drawable。

static boolean isAutoMirrored(Drawable drawable)

当它的布局方向是从右到左的RTL时,告诉它是否自动镜像。

static void jumpToCurrentState(Drawable drawable)

致电 Drawable.jumpToCurrentState()

static void setAutoMirrored(Drawable drawable, boolean mirrored)

设置当其布局方向为RTL(从右到左)时,此Drawable是否自动镜像。

static void setHotspot(Drawable drawable, float x, float y)

指定可绘制内的热点位置。

static void setHotspotBounds(Drawable drawable, int left, int top, int right, int bottom)

设置热点受限的边界,如果它们应该与可绘制边界不同。

static boolean setLayoutDirection(Drawable drawable, int layoutDirection)

设置该drawable的布局方向。

static void setTint(Drawable drawable, int tint)

指定 drawable的色调。

static void setTintList(Drawable drawable, ColorStateList tint)

指定 drawable作为颜色状态列表的色调。

static void setTintMode(Drawable drawable, PorterDuff.Mode tintMode)

指定 drawable的色调混合模式。

static <T extends Drawable> T unwrap(Drawable drawable)

解开 drawable ,如果它是一个调用的结果 wrap(Drawable)

static Drawable wrap(Drawable drawable)

可能包装 drawable以便它可以通过此类中的着色方法在不同的API等级上着色。

继承方法(Inherited methods)

From class java.lang.Object

公共方法(Public methods)

applyTheme

void applyTheme (Drawable drawable, 
                Resources.Theme t)

将指定的主题应用于此Drawable及其子项。

参数(Parameters)
drawable Drawable
t Resources.Theme

canApplyTheme

boolean canApplyTheme (Drawable drawable)

一个主题是否可以应用于这个Drawable及其子节点。

参数(Parameters)
drawable Drawable
返回(Returns)
boolean

getAlpha

int getAlpha (Drawable drawable)

获取drawable的Alpha值。 0表示完全透明,255表示完全不透明。

参数(Parameters)
drawable Drawable: The Drawable against which to invoke the method.
返回(Returns)
int

getColorFilter

ColorFilter getColorFilter (Drawable drawable)

返回当前的颜色过滤器,如果没有设置,则返回 null

参数(Parameters)
drawable Drawable
返回(Returns)
ColorFilter the current color filter, or null if none set

getLayoutDirection

int getLayoutDirection (Drawable drawable)

返回此Drawable的已解析布局方向。

参数(Parameters)
drawable Drawable
返回(Returns)
int One of LAYOUT_DIRECTION_LTR, LAYOUT_DIRECTION_RTL

也可以看看:

inflate

void inflate (Drawable drawable, 
                Resources res, 
                XmlPullParser parser, 
                AttributeSet attrs, 
                Resources.Theme theme)

从可选的由主题设计的XML资源中扩展此Drawable。

参数(Parameters)
drawable Drawable
res Resources: Resources used to resolve attribute values
parser XmlPullParser: XML parser from which to inflate this Drawable
attrs AttributeSet: Base set of attribute values
theme Resources.Theme: Theme to apply, may be null
抛出异常(Throws)
XmlPullParserException
IOException
XmlPullParserException

isAutoMirrored

boolean isAutoMirrored (Drawable drawable)

当它的布局方向是从右到左的RTL时,告诉它是否自动镜像。 LayoutDirection

如果在预先 KITKAT设备上运行,则此方法返回false。

参数(Parameters)
drawable Drawable: The Drawable against which to invoke the method.
返回(Returns)
boolean boolean Returns true if this Drawable will be automatically mirrored.

jumpToCurrentState

void jumpToCurrentState (Drawable drawable)

致电 Drawable.jumpToCurrentState()

如果在 HONEYCOMB设备上运行,此方法不会执行任何操作。

参数(Parameters)
drawable Drawable: The Drawable against which to invoke the method.

setAutoMirrored

void setAutoMirrored (Drawable drawable, 
                boolean mirrored)

设置当其布局方向为RTL(从右到左)时,此Drawable是否自动镜像。 LayoutDirection

如果在 KITKAT设备上运行,此方法不会执行任何操作。

参数(Parameters)
drawable Drawable: The Drawable against which to invoke the method.
mirrored boolean: Set to true if the Drawable should be mirrored, false if not.

setHotspot

void setHotspot (Drawable drawable, 
                float x, 
                float y)

指定可绘制内的热点位置。

参数(Parameters)
drawable Drawable: The Drawable against which to invoke the method.
x float: The X coordinate of the center of the hotspot
y float: The Y coordinate of the center of the hotspot

setHotspotBounds

void setHotspotBounds (Drawable drawable, 
                int left, 
                int top, 
                int right, 
                int bottom)

设置热点受限的边界,如果它们应该与可绘制边界不同。

参数(Parameters)
drawable Drawable: The Drawable against which to invoke the method.
left int
top int
right int
bottom int

setLayoutDirection

boolean setLayoutDirection (Drawable drawable, 
                int layoutDirection)

设置该drawable的布局方向。 应该是已解决的布局方向,因为Drawable没有能力自行完成分辨率。

参数(Parameters)
drawable Drawable
layoutDirection int: the resolved layout direction for the drawable, either LAYOUT_DIRECTION_LTR or LAYOUT_DIRECTION_RTL
返回(Returns)
boolean true if the layout direction change has caused the appearance of the drawable to change such that it needs to be re-drawn, false otherwise

也可以看看:

setTint

void setTint (Drawable drawable, 
                int tint)

指定 drawable的色调。

参数(Parameters)
drawable Drawable: The Drawable against which to invoke the method.
tint int: Color to use for tinting this drawable

setTintList

void setTintList (Drawable drawable, 
                ColorStateList tint)

指定 drawable作为颜色状态列表的色调。

参数(Parameters)
drawable Drawable: The Drawable against which to invoke the method.
tint ColorStateList: Color state list to use for tinting this drawable, or null to clear the tint

setTintMode

void setTintMode (Drawable drawable, 
                PorterDuff.Mode tintMode)

指定 drawable的色调混合模式。

参数(Parameters)
drawable Drawable: The Drawable against which to invoke the method.
tintMode PorterDuff.Mode: A Porter-Duff blending mode

unwrap

T unwrap (Drawable drawable)

解开drawable ,如果它是一个调用的结果wrap(Drawable) 如果drawable不是调用wrap(Drawable)的结果,则drawable返回drawable

参数(Parameters)
drawable Drawable: The drawable to unwrap
返回(Returns)
T the unwrapped Drawable or drawable if it hasn't been wrapped.

也可以看看:

wrap

Drawable wrap (Drawable drawable)

可能包装 drawable以便通过本课程中的着色方法将其用于不同API级别的着色。

您必须使用此调用的结果。 如果给定的drawable被一个视图使用(因为它是背景),你必须用这个调用的结果替换原来的drawable:

 Drawable bg = DrawableCompat.wrap(view.getBackground());
 // Need to set the background with the wrapped drawable
 view.setBackground(bg);

 // You can now tint the drawable
 DrawableCompat.setTint(bg, ...);
 

如果您需要再次获取原始 Drawable ,则可以使用从 unwrap(Drawable)返回的值。

参数(Parameters)
drawable Drawable: The Drawable to process
返回(Returns)
Drawable A drawable capable of being tinted across all API levels.

也可以看看:

Hooray!