当前位置: 首页>>代码示例>>Java>>正文


Java StateSet类代码示例

本文整理汇总了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
            }
    ));
}
 
开发者ID:JMaroz,项目名称:RoundButton,代码行数:21,代码来源:RoundButton.java

示例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();
        }
    }
}
 
开发者ID:nickyangjun,项目名称:EasyEmoji,代码行数:22,代码来源:CommonUtil.java

示例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();
        }
    }
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:20,代码来源:AndroidUtilities.java

示例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;
}
 
开发者ID:OmarAliSaid,项目名称:android-paypal-example,代码行数:25,代码来源:BadgeDrawableBuilder.java

示例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;
}
 
开发者ID:Pingsh,项目名称:Mix,代码行数:30,代码来源:DrawableUtils.java

示例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;
}
 
开发者ID:Pingsh,项目名称:Mix,代码行数:23,代码来源:ColorStateListUtils.java

示例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;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:21,代码来源:ResourceManager.java

示例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);
  }
}
 
开发者ID:commonsguy,项目名称:cwac-crossport,代码行数:27,代码来源:StateListAnimator.java

示例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;
}
 
开发者ID:michael-rapp,项目名称:ChromeLikeTabSwitcher,代码行数:17,代码来源:TabletTabRecyclerAdapter.java

示例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);
        }
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:22,代码来源:StateListAnimator.java

示例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());
}
 
开发者ID:fergus825,项目名称:SmartOrnament,代码行数:20,代码来源:CircularProgressButton.java

示例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);
    }

}
 
开发者ID:shenhuanet,项目名称:OpenEyesReading-android,代码行数:17,代码来源:Util.java

示例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;
}
 
开发者ID:Bilibili,项目名称:MagicaSakura,代码行数:30,代码来源:DrawableUtils.java

示例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);
    }
}
 
开发者ID:GigigoGreenLabs,项目名称:permissionsModule,代码行数:28,代码来源:StateListAnimator.java

示例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;
}
 
开发者ID:sathishmscict,项目名称:AndroidActionItemBadge,代码行数:20,代码来源:BadgeDrawableBuilder.java


注:本文中的android.util.StateSet类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。