本文整理匯總了Java中android.util.StateSet類的典型用法代碼示例。如果您正苦於以下問題:Java StateSet類的具體用法?Java StateSet怎麽用?Java StateSet使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
StateSet類屬於android.util包,在下文中一共展示了StateSet類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: update
import android.util.StateSet; //導入依賴的package包/類
private void update() {
StateListDrawable background = new StateListDrawable();
background.addState(new int[]{android.R.attr.state_pressed}, createDrawable(backgroundColorPressed, cornerColorPressed, cornerWidth, cornerRadius));
background.addState(new int[]{-android.R.attr.state_enabled}, createDrawable(backgroundColorDisabled, cornerColorDisabled, cornerWidth, cornerRadius));
background.addState(StateSet.WILD_CARD, createDrawable(backgroundColor, cornerColor, cornerWidth, cornerRadius));
setBackground(background);
setTextColor(new ColorStateList(
new int[][]{
new int[]{android.R.attr.state_pressed},
new int[]{-android.R.attr.state_enabled},
new int[]{}
},
new int[]{
textColorPressed,
textColorDisabled,
textColor
}
));
}
示例2: clearDrawableAnimation
import android.util.StateSet; //導入依賴的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();
}
}
}
示例3: clearDrawableAnimation
import android.util.StateSet; //導入依賴的package包/類
@SuppressLint("NewApi")
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: build
import android.util.StateSet; //導入依賴的package包/類
public StateListDrawable build(Context ctx) {
StateListDrawable stateListDrawable = new StateListDrawable();
GradientDrawable normal = (GradientDrawable) ContextCompat.getDrawable(ctx, R.drawable.action_item_badge);
GradientDrawable selected = (GradientDrawable) normal.getConstantState().newDrawable().mutate();
normal.setColor(mColor);
selected.setColor(mColorPressed);
if (mStroke > -1) {
normal.setStroke(mStroke, mStrokeColor);
selected.setStroke(mStroke, mStrokeColor);
}
if (mCorners > -1) {
normal.setCornerRadius(mCorners);
selected.setCornerRadius(mCorners);
}
stateListDrawable.addState(new int[]{android.R.attr.state_pressed}, selected);
stateListDrawable.addState(StateSet.WILD_CARD, normal);
return stateListDrawable;
}
示例5: extractStateSet
import android.util.StateSet; //導入依賴的package包/類
/**
* Extracts state_ attributes from an attribute set.
*
* @param attrs The attribute set.
* @return An array of state_ attributes.
*/
protected int[] extractStateSet(AttributeSet attrs) {
int j = 0;
final int numAttrs = attrs.getAttributeCount();
int[] states = new int[numAttrs];
for (int i = 0; i < numAttrs; i++) {
final int stateResId = attrs.getAttributeNameResource(i);
if (stateResId == 0) {
break;
} else if (stateResId == android.R.attr.drawable
|| stateResId == android.R.attr.id
|| stateResId == R.attr.drawableTint
|| stateResId == R.attr.drawableTintMode) {
// Ignore attributes from StateListDrawableItem and
// AnimatedStateListDrawableItem.
continue;
} else {
states[j++] = attrs.getAttributeBooleanValue(i, false)
? stateResId : -stateResId;
}
}
states = StateSet.trimStateSet(states, j);
return states;
}
示例6: extractStateSet
import android.util.StateSet; //導入依賴的package包/類
protected static int[] extractStateSet(AttributeSet attrs) {
int j = 0;
final int numAttrs = attrs.getAttributeCount();
int[] states = new int[numAttrs];
for (int i = 0; i < numAttrs; i++) {
final int stateResId = attrs.getAttributeNameResource(i);
switch (stateResId) {
case 0:
break;
case android.R.attr.color:
case android.R.attr.alpha:
// Ignore attributes from StateListDrawableItem and
// AnimatedStateListDrawableItem.
continue;
default:
states[j++] = attrs.getAttributeBooleanValue(i, false)
? stateResId : -stateResId;
}
}
states = StateSet.trimStateSet(states, j);
return states;
}
示例7: createStateListDrawable
import android.util.StateSet; //導入依賴的package包/類
public static StateListDrawable createStateListDrawable(Context context, String normalPicName, String pressedPicName) {
Drawable normalDrawable;
Drawable pressedDrawable;
if (normalPicName.indexOf(".9") > -1) {
normalDrawable = getNinePatchDrawable(context, normalPicName);
} else {
normalDrawable = getDrawable(context, normalPicName);
}
if (pressedPicName.indexOf(".9") > -1) {
pressedDrawable = getNinePatchDrawable(context, pressedPicName);
} else {
pressedDrawable = getDrawable(context, pressedPicName);
}
StateListDrawable drawable = new StateListDrawable();
drawable.addState(new int[]{16842919}, pressedDrawable);
drawable.addState(new int[]{16842913}, pressedDrawable);
drawable.addState(new int[]{16842908}, pressedDrawable);
drawable.addState(StateSet.WILD_CARD, normalDrawable);
return drawable;
}
示例8: setState
import android.util.StateSet; //導入依賴的package包/類
/**
* Called by View
*/
void setState(int[] state) {
Tuple match = null;
final int count = mTuples.size();
for (int i = 0; i < count; i++) {
final Tuple tuple = mTuples.get(i);
if (StateSet.stateSetMatches(tuple.mSpecs, state)) {
match = tuple;
break;
}
}
if (match == mLastMatch) {
return;
}
if (mLastMatch != null) {
cancel();
}
mLastMatch = match;
if (match != null) {
start(match);
}
}
示例9: onInflateTabView
import android.util.StateSet; //導入依賴的package包/類
@NonNull
@Override
protected final View onInflateTabView(@NonNull final LayoutInflater inflater,
@Nullable final ViewGroup parent,
@NonNull final AbstractTabViewHolder viewHolder) {
View view = inflater.inflate(R.layout.tablet_tab, parent, false);
StateListDrawable backgroundDrawable = new StateListDrawable();
Drawable defaultDrawable = ContextCompat
.getDrawable(getModel().getContext(), R.drawable.tablet_tab_background);
Drawable selectedDrawable = ContextCompat
.getDrawable(getModel().getContext(), R.drawable.tablet_tab_background_selected);
backgroundDrawable.addState(new int[]{android.R.attr.state_selected}, selectedDrawable);
backgroundDrawable.addState(StateSet.WILD_CARD, defaultDrawable);
ViewUtil.setBackground(view, backgroundDrawable);
return view;
}
示例10: setState
import android.util.StateSet; //導入依賴的package包/類
void setState(int[] state) {
Tuple match = null;
int count = this.mTuples.size();
for (int i = 0; i < count; i++) {
Tuple tuple = (Tuple) this.mTuples.get(i);
if (StateSet.stateSetMatches(tuple.mSpecs, state)) {
match = tuple;
break;
}
}
if (match != this.mLastMatch) {
if (this.mLastMatch != null) {
cancel();
}
this.mLastMatch = match;
View view = (View) this.mViewRef.get();
if (match != null && view != null && view.getVisibility() == 0) {
start(match);
}
}
}
示例11: initIdleStateDrawable
import android.util.StateSet; //導入依賴的package包/類
private void initIdleStateDrawable() {
int colorNormal = getNormalColor(mIdleColorState);
int colorPressed = getPressedColor(mIdleColorState);
int colorFocused = getFocusedColor(mIdleColorState);
int colorDisabled = getDisabledColor(mIdleColorState);
if (background == null) {
background = createDrawable(colorNormal);
}
StrokeGradientDrawable drawableDisabled = createDrawable(colorDisabled);
StrokeGradientDrawable drawableFocused = createDrawable(colorFocused);
StrokeGradientDrawable drawablePressed = createDrawable(colorPressed);
mIdleStateDrawable = new StateListDrawable();
mIdleStateDrawable.addState(new int[]{android.R.attr.state_pressed}, drawablePressed.getGradientDrawable());
mIdleStateDrawable.addState(new int[]{android.R.attr.state_focused}, drawableFocused.getGradientDrawable());
mIdleStateDrawable.addState(new int[]{-android.R.attr.state_enabled}, drawableDisabled.getGradientDrawable());
mIdleStateDrawable.addState(StateSet.WILD_CARD, background.getGradientDrawable());
}
示例12: setCircleButtonStateListDrawable
import android.util.StateSet; //導入依賴的package包/類
public void setCircleButtonStateListDrawable(View circleButton, int radius,int color) {
WeakReference<Bitmap> imageNormal = new WeakReference<>(Bitmap.createBitmap(2 * radius, 2 * radius, Bitmap.Config.ARGB_8888));
Canvas canvasNormal = new Canvas(imageNormal.get());
Paint paintNormal = new Paint();
paintNormal.setAntiAlias(true);
paintNormal.setColor(color);
canvasNormal.drawCircle(radius, radius, radius, paintNormal);
StateListDrawable stateListDrawable = new StateListDrawable();
stateListDrawable.addState(StateSet.WILD_CARD, new BitmapDrawable(circleButton.getContext().getResources(), imageNormal.get()));
if (android.os.Build.VERSION.SDK_INT >= 16) {
circleButton.setBackground(stateListDrawable);
} else {
circleButton.setBackgroundDrawable(stateListDrawable);
}
}
示例13: extractStateSet
import android.util.StateSet; //導入依賴的package包/類
/**
* Extracts state_ attributes from an attribute set.
*
* @param attrs The attribute set.
* @return An array of state_ attributes.
*/
static int[] extractStateSet(AttributeSet attrs) {
int j = 0;
final int numAttrs = attrs.getAttributeCount();
int[] states = new int[numAttrs];
for (int i = 0; i < numAttrs; i++) {
final int stateResId = attrs.getAttributeNameResource(i);
if (stateResId == 0) {
break;
} else if (stateResId == android.R.attr.drawable
|| stateResId == android.R.attr.id
|| stateResId == R.attr.drawableTint
|| stateResId == R.attr.drawableTintMode) {
// Ignore attributes from StateListDrawableItem and
// AnimatedStateListDrawableItem.
continue;
} else {
states[j++] = attrs.getAttributeBooleanValue(i, false)
? stateResId : -stateResId;
}
}
states = StateSet.trimStateSet(states, j);
return states;
}
示例14: setState
import android.util.StateSet; //導入依賴的package包/類
/**
* Called by View
*/
void setState(int[] state) {
Tuple match = null;
final int count = mTuples.size();
for (int i = 0; i < count; i++) {
final Tuple tuple = mTuples.get(i);
if (StateSet.stateSetMatches(tuple.mSpecs, state)) {
match = tuple;
break;
}
}
if (match == mLastMatch) {
return;
}
if (mLastMatch != null) {
cancel();
}
mLastMatch = match;
View view = mViewRef.get();
if (match != null && view != null && view.getVisibility() == View.VISIBLE ) {
start(match);
}
}
示例15: build
import android.util.StateSet; //導入依賴的package包/類
public StateListDrawable build(Context ctx) {
StateListDrawable stateListDrawable = new StateListDrawable();
GradientDrawable normal = (GradientDrawable) UIUtil.getCompatDrawable(ctx, R.drawable.action_item_badge);
GradientDrawable selected = (GradientDrawable) normal.getConstantState().newDrawable().mutate();
normal.setColor(mColor);
selected.setColor(mColorPressed);
if (mCorners > -1) {
normal.setCornerRadius(mCorners);
selected.setCornerRadius(mCorners);
}
stateListDrawable.addState(new int[]{android.R.attr.state_pressed}, selected);
stateListDrawable.addState(StateSet.WILD_CARD, normal);
return stateListDrawable;
}