本文整理匯總了Java中android.graphics.drawable.Drawable.setState方法的典型用法代碼示例。如果您正苦於以下問題:Java Drawable.setState方法的具體用法?Java Drawable.setState怎麽用?Java Drawable.setState使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.graphics.drawable.Drawable
的用法示例。
在下文中一共展示了Drawable.setState方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setHotspot
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
void setHotspot(Drawable hotspot) {
if (mHotspot != null) {
mHotspot.setCallback(null);
unscheduleDrawable(mHotspot);
}
if (hotspot != null) {
hotspot.setCallback(this);
if (hotspot.isStateful()) {
hotspot.setState(getDrawableState());
}
}
mHotspot = hotspot;
invalidate();
}
示例2: applyButtonTint
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
void applyButtonTint() {
Drawable buttonDrawable = CompoundButtonCompat.getButtonDrawable(this.mView);
if (buttonDrawable == null) {
return;
}
if (this.mHasButtonTint || this.mHasButtonTintMode) {
buttonDrawable = DrawableCompat.wrap(buttonDrawable).mutate();
if (this.mHasButtonTint) {
DrawableCompat.setTintList(buttonDrawable, this.mButtonTintList);
}
if (this.mHasButtonTintMode) {
DrawableCompat.setTintMode(buttonDrawable, this.mButtonTintMode);
}
if (buttonDrawable.isStateful()) {
buttonDrawable.setState(this.mView.getDrawableState());
}
this.mView.setButtonDrawable(buttonDrawable);
}
}
示例3: clearDrawableAnimation
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
* 清除View(etc:ListView) 拉至頂部或底部的橡皮筋效果
*/
public static void clearDrawableAnimation(View view) {
if (Build.VERSION.SDK_INT < 21 || view == null) {
return;
}
Drawable drawable;
if (view instanceof ListView) {
drawable = ((ListView) view).getSelector();
if (drawable != null) {
drawable.setState(StateSet.NOTHING);
}
} else {
drawable = view.getBackground();
if (drawable != null) {
drawable.setState(StateSet.NOTHING);
drawable.jumpToCurrentState();
}
}
}
示例4: selectBackgroundDrawable
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
* Returns the background drawable for the key, based on the current state and type of the key.
* @return the background drawable of the key.
* @see android.graphics.drawable.StateListDrawable#setState(int[])
*/
@Nonnull
public final Drawable selectBackgroundDrawable(@Nonnull final Drawable keyBackground,
@Nonnull final Drawable functionalKeyBackground,
@Nonnull final Drawable spacebarBackground) {
final Drawable background;
if (mBackgroundType == BACKGROUND_TYPE_FUNCTIONAL) {
background = functionalKeyBackground;
} else if (mBackgroundType == BACKGROUND_TYPE_SPACEBAR) {
background = spacebarBackground;
} else {
background = keyBackground;
}
final int[] state = KeyBackgroundState.STATES[mBackgroundType].getState(mPressed);
background.setState(state);
return background;
}
示例5: setForeground
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
* Supply a Drawable that is to be rendered on top of all of the child
* views in the frame layout. Any padding in the Drawable will be taken
* into account by ensuring that the children are inset to be placed
* inside of the padding area.
*
* @param drawable The Drawable to be drawn on top of the children.
*/
public void setForeground(View view, Drawable drawable) {
if (view != null) {
if (mForeground != drawable) {
if (mForeground != null) {
mForeground.setCallback(null);
view.unscheduleDrawable(mForeground);
}
mForeground = drawable;
if (drawable != null) {
view.setWillNotDraw(false);
drawable.setCallback(view);
if (drawable.isStateful()) {
drawable.setState(view.getDrawableState());
}
if (mForegroundGravity == Gravity.FILL) {
Rect padding = new Rect();
drawable.getPadding(padding);
}
//update bounds
updateBounds(view, drawable);//added by song
} else {
view.setWillNotDraw(true);
}
view.requestLayout();
view.invalidate();
}
}
}
示例6: setOrAnimatePlusCheckIcon
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
public void setOrAnimatePlusCheckIcon(final FloatingActionButton fab, boolean isCheck,
boolean allowAnimate) {
if (!hasL()) {
compatSetOrAnimatePlusCheckIcon(fab, isCheck, allowAnimate);
return;
}
Drawable drawable = fab.getDrawable();
if (!(drawable instanceof AnimatedStateListDrawable)) {
Resources res = mActivity.getResources();
drawable = res.getDrawable(R.drawable.add_schedule_fab_icon_anim);
drawable.setTint(res.getColor(R.color.fab_icon_color));
fab.setImageDrawable(drawable);
}
if (allowAnimate) {
drawable.setState(isCheck ? STATE_UNCHECKED : STATE_CHECKED);
drawable.jumpToCurrentState();
drawable.setState(isCheck ? STATE_CHECKED : STATE_UNCHECKED);
} else {
drawable.setState(isCheck ? STATE_CHECKED : STATE_UNCHECKED);
drawable.jumpToCurrentState();
}
}
示例7: drawableStateChanged
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@Override
protected void drawableStateChanged() {
super.drawableStateChanged();
final int[] state = getDrawableState();
boolean changed = false;
Drawable d = mStatusBarScrim;
if (d != null && d.isStateful()) {
changed |= d.setState(state);
}
d = mContentScrim;
if (d != null && d.isStateful()) {
changed |= d.setState(state);
}
if (mCollapsingTextHelper != null) {
changed |= mCollapsingTextHelper.setState(state);
}
if (changed) {
invalidate();
}
}
示例8: selectBackgroundDrawable
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
* Returns the background drawable for the key, based on the current state and type of the key.
* @return the background drawable of the key.
* @see android.graphics.drawable.StateListDrawable#setState(int[])
*/
@NonNull
public final Drawable selectBackgroundDrawable(@NonNull final Drawable keyBackground,
@NonNull final Drawable functionalKeyBackground,
@NonNull final Drawable spacebarBackground) {
final Drawable background;
if (mBackgroundType == BACKGROUND_TYPE_FUNCTIONAL) {
background = functionalKeyBackground;
} else if (mBackgroundType == BACKGROUND_TYPE_SPACEBAR) {
background = spacebarBackground;
} else {
background = keyBackground;
}
final int[] state = KeyBackgroundState.STATES[mBackgroundType].getState(mPressed);
background.setState(state);
return background;
}
示例9: drawableStateChanged
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@SuppressWarnings("ConstantConditions")
@Override
protected void drawableStateChanged() {
super.drawableStateChanged();
final int[] state = getDrawableState();
boolean changed = false;
Drawable d = mStatusBarScrim;
if (d != null && d.isStateful()) {
changed |= d.setState(state);
}
d = mContentScrim;
if (d != null && d.isStateful()) {
changed |= d.setState(state);
}
if (mCollapsingTextHelper != null) {
changed |= mCollapsingTextHelper.setState(state);
}
if (changed) {
invalidate();
}
}
示例10: setForeground
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
public void setForeground(Drawable drawable) {
if (mForegroundSelector != drawable) {
if (mForegroundSelector != null) {
mForegroundSelector.setCallback(null);
unscheduleDrawable(mForegroundSelector);
}
mForegroundSelector = drawable;
if (drawable != null) {
setWillNotDraw(false);
drawable.setCallback(this);
if (drawable.isStateful()) {
drawable.setState(getDrawableState());
}
} else {
setWillNotDraw(true);
}
requestLayout();
invalidate();
}
}
示例11: drawableStateChanged
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@Override
protected void drawableStateChanged() {
super.drawableStateChanged();
boolean invalidate = false;
for (DrawableInfo drawable : mDrawables) {
Drawable d = drawable.mDrawable;
if (d.isStateful() && d.setState(getDrawableState())) {
invalidate = true;
}
}
if (invalidate) {
invalidate();
}
}
示例12: drawableStateChanged
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@Override
protected void drawableStateChanged() {
super.drawableStateChanged();
final Drawable d = mMarginDrawable;
if (d != null && d.isStateful()) {
d.setState(getDrawableState());
}
}
示例13: drawableStateChanged
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@Override
protected void drawableStateChanged() {
super.drawableStateChanged();
final Drawable d = mMarginDrawable;
if (d != null && d.isStateful()) {
d.setState(getDrawableState());
}
}
示例14: setDrawableState
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private void setDrawableState(Drawable drawable) {
if (drawable != null) {
int[] myDrawableState = getDrawableState();
drawable.setState(myDrawableState);
invalidate();
}
}
示例15: setSelector
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
public void setSelector(Drawable sel) {
if (this.mSelector != null) {
this.mSelector.setCallback(null);
unscheduleDrawable(this.mSelector);
}
this.mSelector = sel;
Rect padding = new Rect();
sel.getPadding(padding);
this.mSelectionLeftPadding = padding.left;
this.mSelectionTopPadding = padding.top;
this.mSelectionRightPadding = padding.right;
this.mSelectionBottomPadding = padding.bottom;
sel.setCallback(this);
sel.setState(getDrawableState());
}